public class MySqlAdapter extends Object implements DbAdapter
Constructor and Description |
---|
MySqlAdapter() |
Modifier and Type | Method and Description |
---|---|
void |
cleanupFailedCheckpoints(String stateId,
Connection con,
long checkpointTs,
long recoveryTs)
Clean up states between the checkpoint and recovery timestamp.
|
void |
compactKvStates(String stateId,
Connection con,
long lowerId,
long upperId)
Compact the states between two checkpoint timestamp by only keeping the
most recent.
|
void |
createCheckpointsTable(String jobId,
Connection con)
Initialize tables for storing non-partitioned checkpoints for the given
job id and database connection.
|
void |
createKVStateTable(String stateId,
Connection con)
Initialize the necessary tables for the given stateId.
|
void |
deleteCheckpoint(String jobId,
Connection con,
long checkpointId,
long checkpointTs,
long handleId)
Remove the given checkpoint from the database.
|
void |
disposeAllStateForJob(String jobId,
Connection con)
Remove all states for the given
JobID ,
by for instance dropping the entire table. |
byte[] |
getCheckpoint(String jobId,
Connection con,
long checkpointId,
long checkpointTs,
long handleId)
Retrieve the serialized checkpoint data from the database.
|
void |
insertBatch(String stateId,
DbBackendConfig conf,
Connection con,
PreparedStatement insertStatement,
long checkpointTs,
List<Tuple2<byte[],byte[]>> toInsert)
Insert a list of Key-Value pairs into the database.
|
void |
keepAlive(Connection con)
Execute a simple operation to refresh the current database connection in
case no data is written for a longer time period.
|
byte[] |
lookupKey(String stateId,
PreparedStatement lookupStatement,
byte[] key,
long lookupTs)
Retrieve the latest value from the database for a given key and
timestamp.
|
PreparedStatement |
prepareCheckpointInsert(String jobId,
Connection con)
Checkpoints will be inserted in the database using prepared statements.
|
String |
prepareKeyLookup(String stateId)
Prepare the statement that will be used to lookup keys from the database.
|
String |
prepareKVCheckpointInsert(String stateId)
Prepare the the statement that will be used to insert key-value pairs in
the database.
|
void |
setCheckpointInsertParams(String jobId,
PreparedStatement insertStatement,
long checkpointId,
long timestamp,
long handleId,
byte[] checkpoint)
Set the
PreparedStatement parameters for the statement returned
by DbAdapter.prepareCheckpointInsert(String, Connection) . |
protected static void |
validateStateId(String name)
Tries to avoid SQL injection with weird state names.
|
public void createCheckpointsTable(String jobId, Connection con) throws SQLException
DbAdapter
createCheckpointsTable
in interface DbAdapter
SQLException
public PreparedStatement prepareCheckpointInsert(String jobId, Connection con) throws SQLException
DbAdapter
prepareCheckpointInsert
in interface DbAdapter
SQLException
public void setCheckpointInsertParams(String jobId, PreparedStatement insertStatement, long checkpointId, long timestamp, long handleId, byte[] checkpoint) throws SQLException
DbAdapter
PreparedStatement
parameters for the statement returned
by DbAdapter.prepareCheckpointInsert(String, Connection)
.setCheckpointInsertParams
in interface DbAdapter
jobId
- Id of the current job.insertStatement
- Statement returned by
DbAdapter.prepareCheckpointInsert(String, Connection)
.checkpointId
- Global checkpoint id.timestamp
- Global checkpoint timestamp.handleId
- Unique id assigned to this state checkpoint (should be primary
key).checkpoint
- The serialized checkpoint.SQLException
public byte[] getCheckpoint(String jobId, Connection con, long checkpointId, long checkpointTs, long handleId) throws SQLException
DbAdapter
getCheckpoint
in interface DbAdapter
jobId
- Id of the current job.con
- Database connectioncheckpointId
- Global checkpoint id.checkpointTs
- Global checkpoint timestamp.handleId
- Unique id assigned to this state checkpoint (should be primary
key).SQLException
public void deleteCheckpoint(String jobId, Connection con, long checkpointId, long checkpointTs, long handleId) throws SQLException
DbAdapter
deleteCheckpoint
in interface DbAdapter
jobId
- Id of the current job.con
- Database connectioncheckpointId
- Global checkpoint id.checkpointTs
- Global checkpoint timestamp.handleId
- Unique id assigned to this state checkpoint (should be primary
key).SQLException
public void disposeAllStateForJob(String jobId, Connection con) throws SQLException
DbAdapter
JobID
,
by for instance dropping the entire table.disposeAllStateForJob
in interface DbAdapter
SQLException
public void createKVStateTable(String stateId, Connection con) throws SQLException
DbAdapter
createKVStateTable
in interface DbAdapter
SQLException
public String prepareKVCheckpointInsert(String stateId) throws SQLException
DbAdapter
prepareKVCheckpointInsert
in interface DbAdapter
SQLException
public String prepareKeyLookup(String stateId) throws SQLException
DbAdapter
prepareKeyLookup
in interface DbAdapter
SQLException
public byte[] lookupKey(String stateId, PreparedStatement lookupStatement, byte[] key, long lookupTs) throws SQLException
DbAdapter
lookupKey
in interface DbAdapter
stateId
- Unique identifier of the kvstate (usually the table name).lookupStatement
- The statement returned by
#prepareKeyLookup(String, Connection)
.key
- The key to lookup.SQLException
public void cleanupFailedCheckpoints(String stateId, Connection con, long checkpointTs, long recoveryTs) throws SQLException
DbAdapter
cleanupFailedCheckpoints
in interface DbAdapter
SQLException
public void compactKvStates(String stateId, Connection con, long lowerId, long upperId) throws SQLException
DbAdapter
compactKvStates
in interface DbAdapter
SQLException
protected static void validateStateId(String name)
public void insertBatch(String stateId, DbBackendConfig conf, Connection con, PreparedStatement insertStatement, long checkpointTs, List<Tuple2<byte[],byte[]>> toInsert) throws IOException
DbAdapter
insertBatch
in interface DbAdapter
IOException
public void keepAlive(Connection con) throws SQLException
DbAdapter
keepAlive
in interface DbAdapter
SQLException
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.