Search in sources :

Example 6 with InvalidEventException

use of com.linkedin.databus.core.InvalidEventException in project databus by linkedin.

the class LoadDataEventsRequestProcessor method process.

@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
    String fileStr = request.getRequiredStringParam(FILE_PATH_PARAM);
    String startWinStr = request.getParams().getProperty(START_WINDOW_PARAM, "false");
    String physicalParitionParameter = request.getParams().getProperty(PHYSICAL_PARTITION_ID_PARAM);
    LOG.info(PHYSICAL_PARTITION_ID_PARAM + "=" + physicalParitionParameter);
    PhysicalPartition pPartition = PhysicalSourceStaticConfig.getDefaultPhysicalPartition();
    if (physicalParitionParameter != null) {
        // physical partition parameter format is PPName_PPId
        pPartition = PhysicalPartition.parsePhysicalPartitionString(physicalParitionParameter, "_");
    }
    boolean startWin = Boolean.valueOf(startWinStr);
    BufferedReader in = new BufferedReader(new FileReader(fileStr));
    try {
        //PhysicalPartition pPartition = new PhysicalPartition(physicalPartitionId);
        // TODO this should actually use DbusEventBufferAppendable (DDSDBUS-78)
        DbusEventBuffer buf = (DbusEventBuffer) _eventBuffer.getDbusEventBufferAppendable(pPartition);
        if (buf == null)
            throw new RequestProcessingException("cannot find buffer for ph. partion " + pPartition);
        if ((buf.getMinScn() < 0) && (buf.getPrevScn() < 0))
            buf.start(0);
        try {
            DbusEventsStatisticsCollector statsCollector = _relay.getInBoundStatsCollectors().getStatsCollector(pPartition.toSimpleString());
            int eventsAppended = 0;
            if (!((eventsAppended = DbusEventSerializable.appendToEventBuffer(in, buf, statsCollector, startWin)) > 0)) {
                throw new RequestProcessingException("event loading failed");
            }
            StringBuilder res = new StringBuilder(20);
            res.append("{\"eventsAppended\":");
            res.append(eventsAppended);
            res.append("}");
            request.getResponseContent().write(ByteBuffer.wrap(res.toString().getBytes(Charset.defaultCharset())));
        } catch (InvalidEventException iee) {
            throw new RequestProcessingException(iee);
        } catch (RuntimeException re) {
            LOG.error("runttime excception: " + re.getMessage(), re);
            throw re;
        }
    } finally {
        in.close();
    }
    return request;
}
Also used : InvalidEventException(com.linkedin.databus.core.InvalidEventException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) DbusEventsStatisticsCollector(com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition) DbusEventBuffer(com.linkedin.databus.core.DbusEventBuffer)

Example 7 with InvalidEventException

use of com.linkedin.databus.core.InvalidEventException in project databus by linkedin.

the class BootstrapPullThread method doSetResumeCheckpoint.

private void doSetResumeCheckpoint(CheckpointMessage cpMessage) {
    _resumeCkpt = cpMessage.getCheckpoint();
    if (null != _resumeCkpt) {
        DbusEventInternalReadable cpEvent = getEventFactory().createCheckpointEvent(_resumeCkpt);
        boolean success;
        try {
            success = _currentState.getDataEventsBuffer().injectEvent(cpEvent);
        } catch (InvalidEventException e) {
            _log.error("unable to create checkpoint event for checkpoint " + _resumeCkpt + "; error: " + e, e);
            success = false;
        }
        if (!success) {
            _log.error("Unable to write bootstrap phase marker");
        }
    }
    _log.info("resume checkpoint: " + _resumeCkpt);
}
Also used : DbusEventInternalReadable(com.linkedin.databus.core.DbusEventInternalReadable) InvalidEventException(com.linkedin.databus.core.InvalidEventException)

Example 8 with InvalidEventException

use of com.linkedin.databus.core.InvalidEventException in project databus by linkedin.

the class BootstrapPullThread method doReadBootstrapEvents.

protected void doReadBootstrapEvents(ConnectionState curState) {
    boolean success = true;
    boolean debugEnabled = _log.isDebugEnabled();
    boolean enqueueMessage = true;
    try {
        Checkpoint cp = curState.getCheckpoint();
        DbusEventBuffer eventBuffer = curState.getDataEventsBuffer();
        if (debugEnabled)
            _log.debug("Sending bootstrap events to buffer");
        //eventBuffer.startEvents();
        DbusEventInternalReadable cpEvent = getEventFactory().createCheckpointEvent(cp);
        byte[] cpEventBytes = new byte[cpEvent.size()];
        if (debugEnabled) {
            _log.debug("checkpoint event size: " + cpEventBytes.length);
            _log.debug("checkpoint event:" + cpEvent.toString());
        }
        cpEvent.getRawBytes().get(cpEventBytes);
        ByteArrayInputStream cpIs = new ByteArrayInputStream(cpEventBytes);
        ReadableByteChannel cpRbc = Channels.newChannel(cpIs);
        UnifiedClientStats unifiedClientStats = _sourcesConn.getUnifiedClientStats();
        sendHeartbeat(unifiedClientStats);
        int ecnt = eventBuffer.readEvents(cpRbc);
        success = (ecnt > 0);
        if (!success) {
            _log.error("Unable to write bootstrap phase marker");
        } else {
            ChunkedBodyReadableByteChannel readChannel = curState.getReadChannel();
            String remoteErrorName = RemoteExceptionHandler.getExceptionName(readChannel);
            Throwable remoteError = _remoteExceptionHandler.getException(readChannel);
            if (null != remoteError && remoteError instanceof BootstrapDatabaseTooOldException) {
                _log.error("Bootstrap database is too old!");
                _remoteExceptionHandler.handleException(remoteError);
                curState.switchToStreamResponseError();
            } else if (null != remoteErrorName) {
                //remote processing error
                _log.error("read events error: " + RemoteExceptionHandler.getExceptionMessage(readChannel));
                curState.switchToStreamResponseError();
            } else {
                sendHeartbeat(unifiedClientStats);
                int eventsNum = eventBuffer.readEvents(readChannel, curState.getListeners(), _sourcesConn.getBootstrapEventsStatsCollector());
                if (eventsNum == 0 && _remoteExceptionHandler.getPendingEventSize(readChannel) > eventBuffer.getMaxReadBufferCapacity()) {
                    String err = "ReadBuffer max capacity(" + eventBuffer.getMaxReadBufferCapacity() + ") is less than event size(" + _remoteExceptionHandler.getPendingEventSize(readChannel) + "). Increase databus.client.connectionDefaults.bstEventBuffer.maxEventSize and restart.";
                    _log.fatal(err);
                    enqueueMessage(LifecycleMessage.createSuspendOnErroMessage(new PendingEventTooLargeException(err)));
                    return;
                } else {
                    resetServerRetries();
                    if (debugEnabled)
                        _log.debug("Sending events to buffer");
                    numEventsInCurrentState += eventsNum;
                    _log.info("Bootstrap events read so far: " + numEventsInCurrentState);
                    String status = readChannel.getMetadata("PhaseCompleted");
                    final BootstrapCheckpointHandler ckptHandler = curState.getBstCheckpointHandler();
                    if (status != null) {
                        // set status in checkpoint to indicate that we are done with the current source
                        if (cp.getConsumptionMode() == DbusClientMode.BOOTSTRAP_CATCHUP) {
                            ckptHandler.finalizeCatchupPhase(cp);
                        } else if (cp.getConsumptionMode() == DbusClientMode.BOOTSTRAP_SNAPSHOT) {
                            ckptHandler.finalizeSnapshotPhase(cp);
                        } else {
                            throw new RuntimeException("Invalid bootstrap phase: " + cp.getConsumptionMode());
                        }
                        _log.info("Bootstrap events read :" + numEventsInCurrentState + " during phase:" + cp.getConsumptionMode() + " [" + cp.getBootstrapSnapshotSourceIndex() + "," + cp.getBootstrapCatchupSourceIndex() + "]");
                        numEventsInCurrentState = 0;
                    } else {
                        // question: how is snapshotOffset maintained in ckpt
                        if (eventsNum > 0) {
                            cp.bootstrapCheckPoint();
                        }
                    }
                    curState.switchToStreamResponseDone();
                }
            }
        }
    } catch (InterruptedException ie) {
        _log.error("interupted", ie);
        success = false;
    } catch (InvalidEventException e) {
        _log.error("error reading events from server: " + e.getMessage(), e);
        success = false;
    } catch (RuntimeException e) {
        _log.error("runtime error reading events from server: " + e.getMessage(), e);
        success = false;
    }
    if (toTearConnAfterHandlingResponse()) {
        tearConnectionAndEnqueuePickServer();
        enqueueMessage = false;
    } else if (!success) {
        curState.switchToPickServer();
    }
    if (enqueueMessage)
        enqueueMessage(curState);
}
Also used : ReadableByteChannel(java.nio.channels.ReadableByteChannel) UnifiedClientStats(com.linkedin.databus.client.pub.mbean.UnifiedClientStats) PendingEventTooLargeException(com.linkedin.databus.core.PendingEventTooLargeException) DbusEventInternalReadable(com.linkedin.databus.core.DbusEventInternalReadable) Checkpoint(com.linkedin.databus.core.Checkpoint) BootstrapCheckpointHandler(com.linkedin.databus.core.BootstrapCheckpointHandler) DbusEventBuffer(com.linkedin.databus.core.DbusEventBuffer) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) Checkpoint(com.linkedin.databus.core.Checkpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) InvalidEventException(com.linkedin.databus.core.InvalidEventException)

Aggregations

InvalidEventException (com.linkedin.databus.core.InvalidEventException)8 DbusEventInternalReadable (com.linkedin.databus.core.DbusEventInternalReadable)4 Checkpoint (com.linkedin.databus.core.Checkpoint)3 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)3 PendingEventTooLargeException (com.linkedin.databus.core.PendingEventTooLargeException)3 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)3 UnifiedClientStats (com.linkedin.databus.client.pub.mbean.UnifiedClientStats)2 PullerRetriesExhaustedException (com.linkedin.databus.core.PullerRetriesExhaustedException)2 ScnNotFoundException (com.linkedin.databus.core.ScnNotFoundException)2 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ReadableByteChannel (java.nio.channels.ReadableByteChannel)2 ChunkedBodyReadableByteChannel (com.linkedin.databus.client.ChunkedBodyReadableByteChannel)1 ServerInfo (com.linkedin.databus.client.pub.ServerInfo)1 BootstrapCheckpointHandler (com.linkedin.databus.core.BootstrapCheckpointHandler)1 DbusErrorEvent (com.linkedin.databus.core.DbusErrorEvent)1 DbusEvent (com.linkedin.databus.core.DbusEvent)1 DbusEventV1 (com.linkedin.databus.core.DbusEventV1)1 DbusEventV2 (com.linkedin.databus.core.DbusEventV2)1 SCNRegressMessage (com.linkedin.databus.core.SCNRegressMessage)1