Class StateStoreMySQLImpl
java.lang.Object
org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreDriver
org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreBaseImpl
org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreSerializableImpl
org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreMySQLImpl
- All Implemented Interfaces:
StateStoreRecordOperations
StateStoreDriver implementation based on MySQL.
There is a separate table for each record type. Each table just as two
columns, recordKey and recordValue.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreSerializableImpl
COLON_MARK, SLASH_MARK -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the State Store driver connection.<T extends BaseRecord>
QueryResult<T>Get all records of the requested record class from the data store.booleanPrepare the driver to access data storage.<T extends BaseRecord>
booleaninitRecordStorage(String className, Class<T> clazz) Initialize storage for a single record class.protected booleaninsertRecord(String tableName, String key, String data) Insert a record with a given key into the specified table.booleanCheck if the driver is currently running and the data store connection is valid.<T extends BaseRecord>
StateStoreOperationResultCreates multiple records.protected booleanrecordExists(String tableName, String key) Checks if a record with a given key existing in the specified table.<T extends BaseRecord>
intRemove multiple records of a specific class that match a query.<T extends BaseRecord>
booleanRemove all records of this class from the store.protected booleanremoveRecord(String tableName, String key) Removes the record with a given key from the specified table.protected booleanupdateRecord(String tableName, String key, String data) Updates the record with a given key from the specified table.Methods inherited from class org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreSerializableImpl
getOriginalPrimaryKey, getPrimaryKey, init, newRecord, serialize, serializeStringMethods inherited from class org.apache.hadoop.hdfs.server.federation.store.driver.impl.StateStoreBaseImpl
get, getMultiple, put, remove, remove, removeMultipleMethods inherited from class org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreDriver
getConf, getIdentifier, getMetrics, getTime, handleOverwriteAndDelete, verifyDriverReady
-
Field Details
-
SQL_STATE_STORE_CONF_PREFIX
- See Also:
-
CONNECTION_URL
- See Also:
-
CONNECTION_USERNAME
- See Also:
-
CONNECTION_PASSWORD
- See Also:
-
CONNECTION_DRIVER
- See Also:
-
-
Constructor Details
-
StateStoreMySQLImpl
public StateStoreMySQLImpl()
-
-
Method Details
-
initDriver
public boolean initDriver()Description copied from class:StateStoreDriverPrepare the driver to access data storage.- Specified by:
initDriverin classStateStoreDriver- Returns:
- True if the driver was successfully initialized. If false is returned, the state store will periodically attempt to re-initialize the driver and the router will remain in safe mode until the driver is initialized.
-
initRecordStorage
Description copied from class:StateStoreDriverInitialize storage for a single record class.- Specified by:
initRecordStoragein classStateStoreDriver- Type Parameters:
T- Type of the state store record.- Parameters:
className- String reference of the record class to initialize, used to construct paths and file names for the record. Determined by configuration settings for the specific driver.clazz- Record type corresponding to the provided name.- Returns:
- True if successful, false otherwise.
-
isDriverReady
public boolean isDriverReady()Description copied from class:StateStoreDriverCheck if the driver is currently running and the data store connection is valid.- Specified by:
isDriverReadyin classStateStoreDriver- Returns:
- True if the driver is initialized and the data store is ready.
-
close
Description copied from class:StateStoreDriverClose the State Store driver connection.- Overrides:
closein classStateStoreDriver- Throws:
Exception- if something goes wrong while closing the state store driver connection.
-
get
Description copied from interface:StateStoreRecordOperationsGet all records of the requested record class from the data store. To use the default implementations in this class, getAll must return new instances of the records on each call. It is recommended to override the default implementations for better performance.- Type Parameters:
T- Record class of the records.- Parameters:
clazz- Class of record to fetch.- Returns:
- List of all records that match the class.
- Throws:
IOException- Throws exception if unable to query the data store.
-
putAll
public <T extends BaseRecord> StateStoreOperationResult putAll(List<T> records, boolean allowUpdate, boolean errorIfExists) throws IOException Description copied from interface:StateStoreRecordOperationsCreates multiple records. Optionally updates existing records that have the same primary key.- Type Parameters:
T- Record class of the records.- Parameters:
records- List of data records to update or create. All records must be of class clazz.allowUpdate- True if update of exiting record is allowed.errorIfExists- True if an error should be returned when inserting an existing record. Only used if allowUpdate = false.- Returns:
- The result of the putAll operation.
- Throws:
IOException- Throws exception if unable to query the data store.
-
removeAll
Description copied from interface:StateStoreRecordOperationsRemove all records of this class from the store.- Type Parameters:
T- Record class of the records.- Parameters:
clazz- Class of records to remove.- Returns:
- True if successful.
- Throws:
IOException- Throws exception if unable to query the data store.
-
remove
Description copied from interface:StateStoreRecordOperationsRemove multiple records of a specific class that match a query. Requires the getAll implementation to fetch fresh records on each call.- Type Parameters:
T- Record class of the records.- Parameters:
clazz- The class to match the records with.query- Query to filter what to remove.- Returns:
- The number of records removed.
- Throws:
IOException- Throws exception if unable to query the data store.
-
insertRecord
Insert a record with a given key into the specified table.- Parameters:
tableName- Name of table to modifykey- Primary key for the record.data- The record value for the given record key.- Returns:
- True is operation is successful, false otherwise.
-
updateRecord
Updates the record with a given key from the specified table.- Parameters:
tableName- Name of table to modifykey- Primary key for the record.data- The record value for the given record key.- Returns:
- True is operation is successful, false otherwise.
-
recordExists
Checks if a record with a given key existing in the specified table.- Parameters:
tableName- Name of table to modifykey- Primary key for the record.- Returns:
- True is operation is successful, false otherwise.
-
removeRecord
Removes the record with a given key from the specified table.- Parameters:
tableName- Name of table to modifykey- Primary key for the record.- Returns:
- True is operation is successful, false otherwise.
-