By default, an error encountered at runtime interrupts the processing of data for the current tuple that caused the error. StreamBase Server reacts to the error according to the type of problem encountered. Some errors are fatal and request the Server to shut down. Other errors are logged while processing continues. The table in Processing Error Tuple Data shows the default response for different types of error conditions.
Starting with StreamBase 5.1.1, you can add error handling to your EventFlow and StreamSQL applications with three features:
-
Error Ports, which you can enable for individual operators or adapters to provide a catch mechanism specific to that operator or adapter.
-
Error Input Streams, which provide a catch mechanism at the application or module level.
-
Error Output Streams, which provide a throw mechanism at the application or module level.
Errors are reported as a tuple in a standardized error tuple format, which can be manipulated as data. You can apply local logic to error processing just as when processing normal tuples.
Error tuples flow from an inner module to its containing module or application, and eventually to the StreamBase Server instance running the application.
Your StreamBase installation includes an Error Streams sample and an Eclipse Cheat Sheet that interactively walks you through several error handling scenarios. See Error Streams Sample for instructions on running this sample.
An Error Port is a special purpose output port that you can optionally enable for all operators, adapters, and module references. The Error Port emits an error tuple for every processing error that occurs inside this operator or adapter, including Java Exceptions that are thrown in custom operators or adapters.
In EventFlow applications, enable Error Ports on the General tab of the Properties view for operators, adapters, and module references. Mark the checkbox next to Enable Error Output Port. This places a red output port on the component's icon in the palette. The red port is a visual reminder that this port is a special case, and that the schema for this port is the standard StreamBase error tuple. The Error Port is always the last output port of each operator or adapter.
In StreamSQL applications, enable error handling with the ERROR
INTO clause. You
can place this clause just before the closing semicolon of any of the StreamSQL data
manipulation statements, as listed on StreamSQL DML.
stream-identifier
An Error Input Stream is a special purpose Input Stream that serves as the error catch mechanism for all otherwise unhandled errors in the containing module or application. There can be only one Error Input Stream in each module or application. Error Input Streams have a predefined schema, which is the schema of the StreamBase error tuple described below.
In EventFlow applications, add an Error Input Stream to a module by dragging the Error Input Stream icon from the Streams drawer of the Palette view to the canvas. The Error Input Stream icon has a single red output port, which is a reminder that the schema for this port is the standard StreamBase error tuple. In StreamSQL applications, add an Error Input Stream with the CREATE ERROR INPUT STREAM statement.
The output port of an Error Input Stream must be connected to another component. The simplest use of an Error Input Stream is to connect its output to a Map or Filter operator, whose output is then connected to an Error Output Stream. This configuration of three components can remain in the canvas alongside the other operators of your application or module. This configuration, illustrated in the following figure, means: enqueue all otherwise unhandled errors in this module at ErrorInput_A, and map its output unchanged to the input of ErrorOutput_B. Error tuples received at ErrorOutput_B are sent to the containing module or application's Error Input Stream.
An Error Output Stream is a special purpose Output Stream that serves as an error throw mechanism for the containing module or application. There can be more than one Error Output Stream per application or module, but the streams of all Error Output Streams in the application or module are sent to the same error output of the module.
In EventFlow applications, add an Error Output Stream to a module by dragging the Error Output Stream icon from the Streams drawer of the Palette view to the canvas. In StreamSQL applications, add an Error Output Stream with the CREATE ERROR OUTPUT STREAM statement.
It is important to distinguish between:
-
an Error Output Stream
-
a standard Output Stream connected to an operator's Error Port
These cases are illustrated in the following figures. In Case 1, the Output Stream
named LoggingOutputStream is not an Error Output Stream. It does have the standard
StreamBase error tuple schema as its schema, but that is because it is
connected to an Error Port. Connecting a stream to an operator's Error Port does not
create an Error Output Stream. That is, such a port does not participate in the throw
mechanism for the containing module or application. It is only a standard stream to
which you are directing error tuples from the operator or adapter with the Error
Port, perhaps for processing farther downstream.
By contrast, the stream named ErrorOutputThrow in Case 2
is a true Error Output Stream. Error tuples from the Astonisher operator are passed on to the next error handler.
|
Case 1: Errors sent to Output Stream for Logging
|
Case 2: Errors are re-raised to the next error handler
A module's Error Output Stream, if any, flows to the containing module or application. This process continues up the chain of modules to the top-level StreamBase application, and then to the StreamBase Server instance running the application. It is the Server that performs the action designated in the action field of each error tuple.
All unhandled errors in a Module Reference go to the same place, regardless of whether they come from an Error Output Stream or are simply unhandled errors. Errors from a Module Reference appear in the same manner as errors from an operator:
-
If the Module Reference has an Error Port, then errors are sent there.
-
Otherwise, if the containing application has an Error Input Stream, then errors are sent there.
-
Otherwise, error tuples continue up the chain of modules.
The standard StreamBase error tuple has the schema shown in the following table.
| Field | Data type | Size | Comments |
|---|---|---|---|
| description | string | 1000 | Contains the error message string. |
| originalTuple | blob | n/a (displayed as -1 in Studio) |
Contains the original failing tuple as a simple human readable blob
consisting of comma-separated field-value pairs in the form (fieldName1=value1, fieldname2=value2, ...) The blob's CSV
pairs must be enclosed in parentheses as shown, to disambiguate the CSV
values of the error tuple itself.
|
| operatorName | string | 200 | Contains the name of the operator in which the error occurred, prefixed with the name of its container. |
| inputPort | int | 4 |
Contains the input port number of operatorName on which the failing tuple
arrived.
|
| nodeName | string | 64 | Contains the host name of the machine running StreamBase Server. |
| type | string | 30 | Contains the error classification according to the Server. See the table in the next section. |
| action | string | 30 |
Contains either shutdown, continue, or ignore. This is
the action ultimately passed to the StreamBase Server running
the application.
|
| time | timestamp | 8 | The time the error occurred. |
The following is an example of an error tuple generated when running the dividemodule.sbapp application from the Error Streams sample
delivered with your StreamBase installation. The error tuple is shown
for clarity with its fields on separate lines, but the error tuple itself is normally
one long comma-separated string.
description=Evaluation exception: Division by zero, originalTuple=(dividend=7568, divisor=0), operatorName=default.DoDivision, inputPort=0, nodeName=cerberus, type=eval-error, action=shutdown, time=2008-01-18 00:24:20.225-0500
Tip
To see the contents of the OriginalTuple field as shown in the example above when running an application in debug mode, go to Eclipse Preferences, open the StreamBase Studio folder, and select Test/Debug. In the Test/Debug page, Select Display blobs as ASCII characters, and change the Maximum blob characters to display to a reasonable number such as 40 or 50.
Your error handling code can read the fields in each error tuple, extracting certain fields for logging purposes. But your code can also manipulate the error tuple data, which can dramatically change how your application operates. The following sections contain a starting point collection of ideas for managing error tuple data. You are by no means restricted to the ideas presented here.
Your error processing code might prepend an application-specific ID string to the description field, and then pass the modified errors downstream. When error tuples arrive downstream, a second error processing operator can extract or sort all tuples with the same ID string.
Your error processing code can extract the failing tuple from the originalTuple field by parsing the CSV values enclosed in parentheses. For simple cases, your code could insert corrected or default data in a field of the failing tuple, and then re-send a corrected tuple downstream.
Note
The format of the originalTuple field is subject to change in future StreamBase releases.
The most dramatic change you can make to your applications is to trap and prevent
Server shutdowns on error conditions. Certain error categories have a default
action type of shutdown, as shown in the table below.
For example, a divide-by-zero error falls in the eval-error category which has a default action of shutdown. Your
error processing code can look for Division by zero in
the description field, paired with eval-error in the
type field. In these cases, your code can change the action field from "shutdown"
to "continue". In this way, you prevent StreamBase Server from
automatically shutting down if an unexpected zero arrives in an incoming tuple
field used as a divisor.
The action field can contain the following values:
-
shutdown — Server error handlers are called, and the shutdown error handler (which always runs last) shuts down the Server.
-
continue — Error handlers are called, but the shutdown error handler does not stop the Server.
-
ignore — Error handlers are not called. The error is simply dropped.
The following table lists the StreamBase error categories and their default actions.
| Error Type | Default Action |
|---|---|
| unknown-type-error | continue |
| fatal-error | shutdown |
| eval-error | shutdown |
| mem-error | shutdown |
| network-error | shutdown |
| xml-error | continue |
| typecheck-error | continue |
| xmlrpc-error | continue |
| db-error | shutdown |
| authentication-error | continue |
| expr-error | continue |
| usage-error | continue |
| plugin-error | shutdown |
| eval-plugin-error | shutdown |
| tuple-error | shutdown |
| config-error | shutdown |
| cluster-network-error | shutdown |
| checkpoint-error | shutdown |
| checkpoint-setup-error | shutdown |
| checkpoint-creation-error | shutdown |
| checkpoint-consumption-error | shutdown |
| page-pool-error | shutdown |
| ha-io-error | shutdown |
| ordering-error | continue |
| adapter-error | continue |
| container-error | continue |
| security-tag-error | continue |
| non-fatal-error | continue |
