GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Documentation
  • Privacy Statement
  • License Agreement
  • Contact Us

This view

  • Original page
  • New address

GeezerVison is showing docs.voltdb.com — Chapter 8. Creating Custom Importers, Exporters, and Formatters

  • Volt Active Data
  • Developer Hub
  • Books
    • VoltDB Tutorial
    • Using VoltDB
    • VoltDB Guide to Performance and Customization
    • VoltDB Administrator's Guide
    • Volt Kubernetes Administrator's Guide
    • VoltDB Quick Reference
  • VoltDB V16
    • VoltDB V16
    • VoltDB V15.3 LTS
    • VoltDB V14.3 LTS
    • VoltDB V13.3 LTS
    • VoltDB V12.3 LTS
    • VoltDB V11.4
    • VoltDB V10.2
    • VoltDB V9.3
Chapter 8. Creating Custom Importers, Exporters, and Formatters

Guide to Performance and Customization

  • Preface▶
    • 1. Organization of this Manual
    • 2. Other Resources
  • 1. Introduction▶
    • 1.1. What Affects Performance?
    • 1.2. How to Use This Book
  • 2. Hello, World! Revisited▶
    • 2.1. Optimizing your Application for VoltDB
    • 2.2. Applying Hello World to a Practical Problem
    • 2.3. Partitioned vs. Replicated Tables
      • 2.3.1. Defining the Partitioning Column
      • 2.3.2. Creating the Stored Procedures
    • 2.4. Using Asynchronous Stored Procedure Calls
      • 2.4.1. Understanding Asynchronous Programming
      • 2.4.2. The Callback Procedure
      • 2.4.3. Making an Asynchronous Procedure Call
    • 2.5. Connecting to all Servers
    • 2.6. Putting it All Together
    • 2.7. Next Steps
  • 3. Understanding VoltDB Execution Plans▶
    • 3.1. How VoltDB Selects Execution Plans for Individual SQL Statements
    • 3.2. Understanding VoltDB Execution Plans
    • 3.3. Reading the Execution Plan and Optimizing Your SQL Statements
      • 3.3.1. Evaluating the Use of Indexes
      • 3.3.2. Evaluating the Table Order for Joins
  • 4. Using Indexes Effectively▶
    • 4.1. Basic Principles for Effective Indexing
    • 4.2. Defining Indexes
    • 4.3. The Goals for Effective Indexing
    • 4.4. How Indexes Work
    • 4.5. Summary
  • 5. Client2, A Modern Java Client Programming Interface (API)▶
    • 5.1. Configuring the Client
    • 5.2. Connecting to the Database
    • 5.3. Calling Procedures
      • 5.3.1. Handling Backpressure
      • 5.3.2. Handling Request Timeouts
      • 5.3.3. Defining Options on a Per-Call Basis
  • 6. Creating Flexible Schemas With JSON▶
    • 6.1. Using JSON Data Structures as VoltDB Content
    • 6.2. Querying JSON Data
    • 6.3. Updating JSON Data
    • 6.4. Indexing JSON Fields
    • 6.5. Summary: Using JSON in VoltDB
  • 7. Creating Geospatial Applications▶
    • 7.1. The Geospatial Datatypes
      • 7.1.1. The GEOGRAPHY_POINT Datatype
      • 7.1.2. The GEOGRAPHY Datatype
      • 7.1.3. Sizing GEOGRAPHY Columns
      • 7.1.4. How Geospatial Values are Interpreted
    • 7.2. Entering Geospatial Data
    • 7.3. Working With Geospatial Data
      • 7.3.1. Working With Locations
      • 7.3.2. Working With Regions
  • 8. Creating Custom Importers, Exporters, and Formatters▶
    • 8.1. Writing a Custom Exporter
      • 8.1.1. The Structure and Workflow of the Export Client
      • 8.1.2. How to Use Custom Properties to Configure the Client
      • 8.1.3. How to Compile and Install the Client
      • 8.1.4. How to Configure the Export Client
    • 8.2. Writing a Custom Importer
      • 8.2.1. Designing and Coding a Custom Importer
      • 8.2.2. Packaging and Installing a Custom Importer
      • 8.2.3. Configuring and Running a Custom Importer
    • 8.3. Writing a Custom Formatter
      • 8.3.1. The Structure of the Custom Formatter
      • 8.3.2. Compiling and Packaging Custom Formatter Bundles
      • 8.3.3. Installing and Invoking Custom Formatters
      • 8.3.4. Using Custom Formatters With the kafkaloader Utility
  • 9. Creating Custom Tasks▶
    • 9.1. Overview of How Custom Tasks Work
    • 9.2. Modifying the Procedure Call and Arguments
      • 9.2.1. Designing a Java Class That Implements ActionGenerator
      • 9.2.2. Compiling and Loading the Class into VoltDB
      • 9.2.3. Declaring the Task
    • 9.3. Modifying the Interval Between Invocations
      • 9.3.1. Designing a Java Class That Implements IntervalGenerator
      • 9.3.2. Compiling and Loading the Class into VoltDB
      • 9.3.3. Declaring the Task
    • 9.4. Modifying Both the Procedure and Interval
      • 9.4.1. Designing a Java Class That Implements ActionScheduler
      • 9.4.2. Compiling and Loading the Class into VoltDB
      • 9.4.3. Declaring the Task
  • 10. Using Compound Procedures▶
    • 10.1. How Compound Procedures Work
    • 10.2. Defining the Compound Procedure
    • 10.3. Compiling and Loading the Compound Procedure
    • 10.4. Declaring the Compound Procedure
    • 10.5. Invoking the Compound Procedure
    • 10.6. Handling Errors
    • 10.7. Managing Compound Procedures and System Resources
  • 11. Understanding Memory Usage▶
    • 11.1. How the Database Uses Memory
    • 11.2. Actions that Impact Memory Usage
    • 11.3. How the Database Manages Memory
    • 11.4. How Memory is Allocated and Deallocated
    • 11.5. Controlling How Memory is Allocated and Used
      • 11.5.1. Managing the Java Heap
      • 11.5.2. Controlling the Compaction Process for Table Data
    • 11.6. Understanding Memory Usage for Specific Applications
  • 12. Managing Time▶
    • 12.1. The Importance of Time
    • 12.2. Using NTP to Manage Time
      • 12.2.1. Basic Configuration
      • 12.2.2. Troubleshooting Issues with Time
      • 12.2.3. Correcting Common Problems with Time
      • 12.2.4. Example NTP Configuration
    • 12.3. Configuring NTP in a Hosted, Virtual, or Cloud Environment
      • 12.3.1. Considerations for Hosted Environments
      • 12.3.2. Considerations for Virtual and Cloud Environments

Chapter 8. Creating Custom Importers, Exporters, and Formatters

VoltDB includes built-in export and import connectors for a number of standard formats, such as CSV files, JDBC, Kafka topics, and so on. If you have a data source or destination not currently covered by connectors provided by VoltDB, you could write a custom application to perform the translation. However, you would then need to manually coordinate the starting and stopping of your application with the starting and stopping of the database.

A better approach is to create a custom import or export connector. Custom connectors run within the VoltDB process and use the standard mechanisms in VoltDB for synchronizing the running of the connector with the database itself. You write custom connectors as Java classes, packaged in a JAR file, which VoltDB can access at runtime. This chapter provides instructions and sample code for writing, installing, and configuring custom export and import connectors. It also describes how to write custom formatters that can be used to interpret the input coming from an import connector.

8.1. Writing a Custom Exporter

Warning

Note that the VoltDB export subsystem has been extensively enhanced and improved and the original custom export interface is now deprecated, since it no longer supports all the necessary features. The following sections describe the latest custom interface (introduced in VoltDB V8), which uses the same method names, but uses different signatures.

To use the new, supported interface, the onBlockStart(), onBlockCompletion(), and processRow() methods must accept a single exportRow object, as described in the following sections. The older, deprecated interface where the methods accept no arguments, or in the case of processRow(), two arguments, will no longer be supported after the next major release.

An export connector, known internally as an ExportClient, is a Java class that receives blocks of row data when data is inserted into a stream within the database. The export connector is responsible for formatting and passing those rows to the downstream export target. The following sections describe:

  • The Structure and Workflow of the Export Client

  • How to Use Custom Properties to Configure the Client

  • How to Compile and Install the Client

  • How to Configure the Export Client

8.1.1. The Structure and Workflow of the Export Client

The custom export client is declared as a Java subclass extending ExportClientBase. Within the subclass you can override the configure() method, which receives any properties defined in the export connection configuration. The subclass must also declare the constructExportDecoder() method, which in turn generates a subclass of ExportDecoderBase. This extension of ExportDecoderBase is the class that does the actual work at run time and must override the primary methods sourceNoLongerAdvertised(), onBlockStart(), processRow(), and onBlockCompletion. Figure 8.1, “Structure of the Custom Export Class” illustrates the structure of the custom client.

Figure 8.1. Structure of the Custom Export Class

Structure of the Custom Export Class

At run time, VoltDB passes data to the export client in blocks that are roughly 2MB in size but do not align with transactions. A block is guaranteed to contain complete rows — that is, no single SQL INSERT to an export stream is split across blocks. The handoff from the internal VoltDB producer to the custom export client follows a simple pattern:

producer -> client.onBlockStart
foreach row in block:
    producer -> client.processRow
producer -> client.onBlockCompletion

Each time the pattern executes, it runs within a single thread. Therefore, it is not necessary to synchronize accesses to the data structures used in client.onBlockStart, client.processRow, and client.onBlockCompletion unless they are used in other threads as well.

For each row of data, the processRow() method is called. The object passed in as an argument contains a full description of the row, including the column names, types, and values, which your client code can iterate over. For example:

public boolean processRow(ExportRow row) 
               throws RestartBlockException {

   for (int i =0; i < row.values.length; i++) {
      String column_name = row.names.get(i);
      Object column_value = row.values[i];
          // do work . . .
   }

Note that each row starts with six columns of metadata, including the transaction ID and timestamp. If you do not need this information, you can skip the first six columns. Also, within each block of export data, the schema is constant. However, it is possible for the schema to change between blocks (if a schema change is applied to the database while export is active). The custom client can evaluate the ExportRow object passed into the onBlockStart() or processRow() method to recognize any changes to the schema and configure the downstream system as necessary to accept the new data.

As a rule, the custom client must balance the requirements to execute and return control quickly, so as not to block other export threads (since connectors share a limited thread pool), against the need to ensure that the individual rows are accepted and acknowledged by the downstream system before onBlockCompletion() returns. If the client fails at onBlockStart, processRow or onBlockCompletion, the export client must throw a RestartBlockException to prevent VoltDB from acknowledging (ACKing) and dropping the export data from its durability control. This point deserves repeating: if the custom ExportClient runs onBlockStart, processRow and onBlockCompletion without throwing the correct exception, VoltDB assumes the data is remotely durable and that the VoltDB database can discard that export block.

The ExportClient must not return from onBlockCompletion until it ensures the downstream target acknowledges receipt of the data.

8.1.2. How to Use Custom Properties to Configure the Client

Properties, set in the deployment file as part of the export configuration, let you pass information to the export connector. For example, if the user needs to pass the export connector a file location or IP address for the export target. What properties are necessary or supported is up to you as the author of the export client to decide.

The properties specified in the deployment file are passed to the export client as a Properties object argument to the configure() method every time the connector starts. That is, whenever the database starts with the connector enabled or whenever the schema or deployment is modified (for example, by a voltadmin update command).

The configure() method can either iterate over the Properties object or it can look for specific entries as needed. For example:

public void configure(Properties config) throws Exception {
  
        // Check for specific property value
    if config.containsKey("filename") {
       filename = config.getProperty("filename");
     }   
}

8.1.3. How to Compile and Install the Client

Once your export client code is complete, you need to compile, package, and install the connector on the appropriate VoltDB servers. You compile the export client like other Java methods. Be sure to include the VoltDB server jar file in the classpath. For example, if VoltDB is installed in a directory called voltdb in your home directory, the command could be:

$ javac -cp "$HOME/voltdb/voltdb/*:./" -d obj \
   org.voltdb.exportclient/MyExportClient.java

After compiling the source code, you must package the resulting class into a JAR file, like so:

$ jar cvf myexportclient.jar -C obj .

Finally you must install the JAR file in the lib/extension folder where VoltDB is installed on all servers in the cluster that will be running the export client. For, example, if you are running a single node cluster on the current node, where VoltDB has been installed as $HOME/voltdb, you can copy the JAR file with the following command:

$ cp myexportclient.jar $HOME/voltdb/lib/extension/

8.1.4. How to Configure the Export Client

Once your custom export client is installed you can configure and start it. Custom export clients are configured like any other export connector, by adding a deployment.export.configurations list element to the configuration, either when initializing the database or using voltadmin set or update command once the database is running. For custom clients, you declare the connector type as "custom" and add the exportconnectorclass property specifying the connector's Java classpath. For example:

deployment:
  export:
    configurations:
    - enabled: true
      target: myspecial
      type: custom 
      exportconnectorclass: org.voltdb.exportclient.MyExportClient
      properties:
      - name: filename
        value: exportfile.txt

Any properties listed in the deployment.export.configuration.property array ("filename" in this example) are passed to the custom export client as arguments to the configure() method, as described in Section 8.1.2, “How to Use Custom Properties to Configure the Client”. See the chapter on "Importing and Exporting Live Data" in the Using VoltDB manual for more information on configuring export connectors.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.