org.apache.hadoop.hive.ql.lockmgr
Interface HiveTxnManager

All Known Implementing Classes:
DbTxnManager

public interface HiveTxnManager

An interface that allows Hive to manage transactions. All classes implementing this should extend HiveTxnManagerImpl rather than implementing this directly.


Method Summary
 void acquireLocks(QueryPlan plan, Context ctx, String username)
          Acquire all of the locks needed by a query.
 void closeTxnManager()
          This call closes down the transaction manager.
 void commitTxn()
          Commit the current transaction.
 HiveLockManager getLockManager()
          Get the lock manager.
 ValidTxnList getValidTxns()
          Get the transactions that are currently valid.
 void heartbeat()
          Send a heartbeat to the transaction management storage so other Hive clients know that the transaction and locks held by this client are still valid.
 void openTxn(String user)
          Open a new transaction.
 void rollbackTxn()
          Abort the current transaction.
 boolean supportsExplicitLock()
          Indicate whether this lock manager supports the use of lock database or lock table.
 boolean useNewShowLocksFormat()
          Indicate whether this transaction manager returns information about locks in the new format for show locks or the old one.
 

Method Detail

openTxn

void openTxn(String user)
             throws LockException
Open a new transaction.

Parameters:
user - Hive user who is opening this transaction.
Throws:
LockException - if a transaction is already open.

getLockManager

HiveLockManager getLockManager()
                               throws LockException
Get the lock manager. This must be used rather than instantiating an instance of the lock manager directly as the transaction manager will choose which lock manager to instantiate.

Returns:
the instance of the lock manager
Throws:
LockException - if there is an issue obtaining the lock manager.

acquireLocks

void acquireLocks(QueryPlan plan,
                  Context ctx,
                  String username)
                  throws LockException
Acquire all of the locks needed by a query. If used with a query that requires transactions, this should be called after openTxn(String). A list of acquired locks will be stored in the Context object and can be retrieved via Context.getHiveLocks().

Parameters:
plan - query plan
ctx - Context for this query
username - name of the user for this query
Throws:
LockException - if there is an error getting the locks

commitTxn

void commitTxn()
               throws LockException
Commit the current transaction. This will release all locks obtained in acquireLocks(org.apache.hadoop.hive.ql.QueryPlan, org.apache.hadoop.hive.ql.Context, java.lang.String).

Throws:
LockException - if there is no current transaction or the transaction has already been committed or aborted.

rollbackTxn

void rollbackTxn()
                 throws LockException
Abort the current transaction. This will release all locks obtained in acquireLocks(org.apache.hadoop.hive.ql.QueryPlan, org.apache.hadoop.hive.ql.Context, java.lang.String).

Throws:
LockException - if there is no current transaction or the transaction has already been committed or aborted.

heartbeat

void heartbeat()
               throws LockException
Send a heartbeat to the transaction management storage so other Hive clients know that the transaction and locks held by this client are still valid. For implementations that do not require heartbeats this can be a no-op.

Throws:
LockException - If current transaction exists or the transaction has already been committed or aborted.

getValidTxns

ValidTxnList getValidTxns()
                          throws LockException
Get the transactions that are currently valid. The resulting ValidTxnList object is a thrift object and can be passed to the processing tasks for use in the reading the data. This call should be made once up front by the planner and should never be called on the backend, as this will violate the isolation level semantics.

Returns:
list of valid transactions.
Throws:
LockException

closeTxnManager

void closeTxnManager()
This call closes down the transaction manager. All open transactions are aborted. If no transactions are open but locks are held those locks are released. This method should be called if processing of a session is being halted in an abnormal way. It avoids locks and transactions timing out.


supportsExplicitLock

boolean supportsExplicitLock()
Indicate whether this lock manager supports the use of lock database or lock table.

Returns:

useNewShowLocksFormat

boolean useNewShowLocksFormat()
Indicate whether this transaction manager returns information about locks in the new format for show locks or the old one.

Returns:
true if the new format should be used.


Copyright © 2014 The Apache Software Foundation. All rights reserved.