zhisheng17/flink-learning · error · RuntimeException

This ${database} database does not exist!

Error message

This ${database} database does not exist!

What it means

InfluxDBSink.open checks whether the configured database exists in InfluxDB before writing. If it does not exist and influxDBConfig.isCreateDatabase() is false, the sink fails fast with a RuntimeException naming the missing database.

Source

Thrown at flink-learning-connectors/flink-learning-connectors-influxdb/src/main/java/com/zhisheng/connectors/influxdb/InfluxDBSink.java:42

    private final InfluxDBConfig influxDBConfig;

    public InfluxDBSink(InfluxDBConfig influxDBConfig) {
        this.influxDBConfig = Preconditions.checkNotNull(influxDBConfig, "InfluxDB client config should not be null");
    }

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);

        influxDBClient = InfluxDBFactory.connect(influxDBConfig.getUrl(), influxDBConfig.getUsername(), influxDBConfig.getPassword());

        if (!influxDBClient.databaseExists(influxDBConfig.getDatabase())) {
            if(influxDBConfig.isCreateDatabase()) {
                influxDBClient.createDatabase(influxDBConfig.getDatabase());
            }
            else {
                throw new RuntimeException("This " + influxDBConfig.getDatabase() + " database does not exist!");
            }
        }

        influxDBClient.setDatabase(influxDBConfig.getDatabase());

        if (influxDBConfig.getBatchActions() > 0) {
            influxDBClient.enableBatch(influxDBConfig.getBatchActions(), influxDBConfig.getFlushDuration(), influxDBConfig.getFlushDurationTimeUnit());
        }

        if (influxDBConfig.isEnableGzip()) {
            influxDBClient.enableGzip();
        }
    }

    @Override
    public void invoke(MetricEvent metricEvent, Context context) throws Exception {
        if (StringUtils.isNullOrWhitespaceOnly(metricEvent.getName())) {
            throw new RuntimeException("No measurement defined");

View on GitHub (pinned to d731cee761)

Solutions

  1. Create the database in InfluxDB first: CREATE DATABASE "mydb" (or HTTP /query?q=CREATE DATABASE%20"mydb")
  2. Enable auto-creation by setting createDatabase(true) on InfluxDBConfig
  3. Fix the database name typo in the sink config

Example fix

// before
InfluxDBConfig config = new InfluxDBConfig.Builder("http://localhost:8086", "metrics").build();
// after
InfluxDBConfig config = new InfluxDBConfig.Builder("http://localhost:8086", "metrics")
    .createDatabase(true)
    .build();
Defensive patterns

Strategy: fallback

Validate before calling

// before creating the sink
try (InfluxDB influxDB = InfluxDBFactory.connect(url)) {
    if (!influxDB.databaseExists(database)) {
        influxDB.createDatabase(database);
    }
}

Try / catch

try {
    sink.open(ctx);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().contains("database does not exist")) {
        influxDB.createDatabase(config.getDatabase());
        sink.open(ctx);
    } else throw e;
}

Prevention

When it happens

Trigger: Opening the InfluxDBSink connected to an InfluxDB instance where the database named in InfluxDBConfig.getDatabase() does not exist, with the createDatabase flag left at false.

Common situations: Deploying to a fresh InfluxDB instance without creating the database, typos in the database name in config, or environments where CREATE DATABASE requires privileges the sink does not have so auto-creation was disabled.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of zhisheng17/flink-learning@d731cee761 (2026-09-06). Data as JSON: /api/errors/114344e4415a420b. Report an issue: GitHub.