public boolean isTablePresent(TableName tableName) throws IOException { ReadWriteLock lock = tnLock.getLock(tableName); lock.readLock().lock(); try { return readMetaState(tableName) != null; } finally { lock.readLock().unlock(); } }
@NonNull public TableState getTableState(TableName tableName) throws IOException { ReadWriteLock lock = tnLock.getLock(tableName); lock.readLock().lock(); try { TableState currentState = readMetaState(tableName); if (currentState == null) { throw new TableStateNotFoundException(tableName); } return currentState; } finally { lock.readLock().unlock(); } }
/** * Set table state to provided but only if table not in specified states Caller should lock table * on write. * @param tableName table to change state for * @param newState new state * @param states states to check against */ public boolean setTableStateIfNotInStates(TableName tableName, TableState.State newState, TableState.State... states) throws IOException { ReadWriteLock lock = tnLock.getLock(tableName); lock.writeLock().lock(); try { TableState currentState = readMetaState(tableName); if (currentState == null) { throw new TableNotFoundException(tableName); } if (!currentState.inStates(states)) { updateMetaState(tableName, newState); return true; } else { return false; } } finally { lock.writeLock().unlock(); } }
/** * Set table state to provided but only if table in specified states Caller should lock table on * write. * @param tableName table to change state for * @param newState new state * @param states states to check against * @return null if succeed or table state if failed */ public TableState setTableStateIfInStates(TableName tableName, TableState.State newState, TableState.State... states) throws IOException { ReadWriteLock lock = tnLock.getLock(tableName); lock.writeLock().lock(); try { TableState currentState = readMetaState(tableName); if (currentState == null) { throw new TableNotFoundException(tableName); } if (currentState.inStates(states)) { updateMetaState(tableName, newState); return null; } else { return currentState; } } finally { lock.writeLock().unlock(); } }