{"record":{"id":"e542ca0e9b361dc0","repo":"pentaho/pentaho-kettle","slug":"unable-to-get-next-value-for-slave-sequence-name-on-database","errorCode":null,"errorMessage":"Unable to get next value for slave sequence '\" + name + \"' on database '\" + databaseMeta.getName() + \"'","messagePattern":"Unable to get next value for slave sequence '\" \\+ name \\+ \"' on database '\" \\+ databaseMeta\\.getName\\(\\) \\+ \"'","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/www/SlaveSequence.java","lineNumber":144,"sourceCode":"      //\n      if ( update ) {\n        sql = \"UPDATE \" + schemaTable + \" SET \" + valField + \"= ? WHERE \" + seqField + \"= ? \";\n        param = new RowMetaAndData();\n        param.addValue( valField, ValueMetaInterface.TYPE_INTEGER, Long.valueOf( maximum ) );\n        param.addValue( seqField, ValueMetaInterface.TYPE_STRING, name );\n\n      } else {\n        sql = \"INSERT INTO \" + schemaTable + \"(\" + seqField + \", \" + valField + \") VALUES( ? , ? )\";\n        param = new RowMetaAndData();\n        param.addValue( seqField, ValueMetaInterface.TYPE_STRING, name );\n        param.addValue( valField, ValueMetaInterface.TYPE_INTEGER, Long.valueOf( maximum ) );\n      }\n      db.execStatement( sql, param.getRowMeta(), param.getData() );\n\n      return value;\n\n    } catch ( Exception e ) {\n      throw new KettleException( \"Unable to get next value for slave sequence '\"\n        + name + \"' on database '\" + databaseMeta.getName() + \"'\", e );\n    } finally {\n      db.close();\n    }\n  }\n\n  public SlaveSequence( Node node, List<DatabaseMeta> databases ) throws KettleXMLException {\n    name = XMLHandler.getTagValue( node, \"name\" );\n    startValue = Const.toInt( XMLHandler.getTagValue( node, \"start\" ), 0 );\n    databaseMeta = DatabaseMeta.findDatabase( databases, XMLHandler.getTagValue( node, \"connection\" ) );\n    schemaName = XMLHandler.getTagValue( node, \"schema\" );\n    tableName = XMLHandler.getTagValue( node, \"table\" );\n    sequenceNameField = XMLHandler.getTagValue( node, \"sequence_field\" );\n    valueField = XMLHandler.getTagValue( node, \"value_field\" );\n  }\n\n  public String getXML() {\n    StringBuilder xml = new StringBuilder( 100 );","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/www/SlaveSequence.java#L126-L162","documentation":"SlaveSequence.getNextValue fetches the next value of a Carte 'slave sequence' (a sequence used to coordinate clustered transformation runs) from the underlying database, wrapping any failure (SQL error, sequence missing, connection failure) in a KettleException that names the sequence and database. The database handle is always closed in the finally block. It means the DB-side increment for the slave sequence could not be performed.","triggerScenarios":"nextValue(name) called during clustered/partitioned run setup while the backing database is unreachable, the SEQUENCE table/sequence object was dropped, or the generated SQL is invalid for that database dialect.","commonSituations":"Carte slave nodes configured with auto-sequence against a database that was migrated/renamed; DB user lacks SELECT/ALTER on the sequence; sequence schema created on one DB type (e.g. Oracle) but Carte points at another (e.g. PostgreSQL) where the SQL is invalid.","solutions":["Inspect the chained cause e for the actual SQL error from databaseMeta.getName() target.","Verify the database connection defined for the slave sequence (host, port, credentials) works from the Carte node.","Check the sequence/table backing the slave sequence still exists and the DB user has privileges on it.","Recreate the slave sequence (or let SlaveServerConfig.readAutoSequences recreate it) if it was dropped.","Confirm the database dialect matches the actual DBMS so the generated sequence SQL is valid."],"exampleFix":"// before: sequence points at a dead host\nSequenceMeta seq = new SequenceMeta(\"cluster_seq\", dbMetaOn(\"10.0.0.9\", \"seqdb\"), ...);\n\n// after: point at a reachable, verified database\nDatabaseMeta db = dbMetaOn(\"10.0.0.5\", \"seqdb\"); // verified with a test connection\nSequenceMeta seq = new SequenceMeta(\"cluster_seq\", db, ...);","handlingStrategy":"try-catch","validationCode":"// verify the sequence DB is reachable before starting clustered runs\nDatabaseMeta db = ...;\ntry (Connection c = DriverManager.getConnection(db.getURL(), db.getUsername(), db.getPassword())) {\n  if (!c.isValid(5)) throw new SQLException(\"sequence DB not reachable\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  long v = slaveSequence.nextValue(name);\n} catch (KettleException e) {\n  log.error(\"Slave sequence '{}' failed on db '{}': {}\", name, dbName, e.getCause(), e);\n  // alert / fail the cluster startup; do not retry blindly if the cause is SQL/privilege related\n}","preventionTips":["Health-check the sequence database in Carte startup scripts.","Grant the DB account the privileges needed to select/increment sequences.","Back up and restore sequence rows when migrating the sequence DB."],"tags":["database","sequence","carte","clustering","sql"],"backgroundTag":"sql-query-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}