@Test public void testSysMutexCheckReturnsFalseWhenTableAbsent() throws Exception { doThrow(new TableNotFoundException()) .when(mockAdmin) .getDescriptor(TableName.valueOf(SYSTEM_MUTEX_NAME)); doThrow(new TableNotFoundException()) .when(mockAdmin) .getDescriptor(TableName.valueOf(SYSTEM_SCHEMA_NAME, SYSTEM_MUTEX_TABLE_NAME)); assertFalse(mockCqs.checkIfSysMutexExistsAndModifyTTLIfRequired(mockAdmin)); }
@VisibleForTesting boolean checkIfSysMutexExistsAndModifyTTLIfRequired(Admin admin) throws IOException { TableDescriptor htd; try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_MUTEX_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored) { try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_SCHEMA_NAME, SYSTEM_MUTEX_TABLE_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored2) { return false; } } if (htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES).getTimeToLive() != TTL_FOR_MUTEX) { LOGGER.debug("SYSTEM MUTEX already appears to exist, but has the wrong TTL. " + "Will modify the TTL"); ColumnFamilyDescriptor hColFamDesc = ColumnFamilyDescriptorBuilder .newBuilder(htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES)) .setTimeToLive(TTL_FOR_MUTEX) .build(); htd = TableDescriptorBuilder .newBuilder(htd) .modifyColumnFamily(hColFamDesc) .build(); admin.modifyTable(htd); } else { LOGGER.debug("SYSTEM MUTEX already appears to exist with the correct TTL, " + "not creating it"); } return true; }
ConnectionQueryServicesImpl extends DelegateQueryServices implements ConnectionQueryServices { @VisibleForTesting boolean checkIfSysMutexExistsAndModifyTTLIfRequired(Admin admin) throws IOException { TableDescriptor htd; try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_MUTEX_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored) { try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_SCHEMA_NAME, SYSTEM_MUTEX_TABLE_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored2) { return false; } } if (htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES).getTimeToLive() != TTL_FOR_MUTEX) { LOGGER.debug("SYSTEM MUTEX already appears to exist, but has the wrong TTL. " + "Will modify the TTL"); ColumnFamilyDescriptor hColFamDesc = ColumnFamilyDescriptorBuilder .newBuilder(htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES)) .setTimeToLive(TTL_FOR_MUTEX) .build(); htd = TableDescriptorBuilder .newBuilder(htd) .modifyColumnFamily(hColFamDesc) .build(); admin.modifyTable(htd); } else { LOGGER.debug("SYSTEM MUTEX already appears to exist with the correct TTL, " + "not creating it"); } return true; } }
ConnectionQueryServicesImpl extends DelegateQueryServices implements ConnectionQueryServices { @VisibleForTesting boolean checkIfSysMutexExistsAndModifyTTLIfRequired(Admin admin) throws IOException { TableDescriptor htd; try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_MUTEX_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored) { try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_SCHEMA_NAME, SYSTEM_MUTEX_TABLE_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored2) { return false; } } if (htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES).getTimeToLive() != TTL_FOR_MUTEX) { LOGGER.debug("SYSTEM MUTEX already appears to exist, but has the wrong TTL. " + "Will modify the TTL"); ColumnFamilyDescriptor hColFamDesc = ColumnFamilyDescriptorBuilder .newBuilder(htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES)) .setTimeToLive(TTL_FOR_MUTEX) .build(); htd = TableDescriptorBuilder .newBuilder(htd) .modifyColumnFamily(hColFamDesc) .build(); admin.modifyTable(htd); } else { LOGGER.debug("SYSTEM MUTEX already appears to exist with the correct TTL, " + "not creating it"); } return true; } ConnectionQueryServicesImpl(QueryServices services, ConnectionInfo connectionInfo, Properties info); }
ConnectionQueryServicesImpl extends DelegateQueryServices implements ConnectionQueryServices { @VisibleForTesting boolean checkIfSysMutexExistsAndModifyTTLIfRequired(Admin admin) throws IOException { TableDescriptor htd; try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_MUTEX_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored) { try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_SCHEMA_NAME, SYSTEM_MUTEX_TABLE_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored2) { return false; } } if (htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES).getTimeToLive() != TTL_FOR_MUTEX) { LOGGER.debug("SYSTEM MUTEX already appears to exist, but has the wrong TTL. " + "Will modify the TTL"); ColumnFamilyDescriptor hColFamDesc = ColumnFamilyDescriptorBuilder .newBuilder(htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES)) .setTimeToLive(TTL_FOR_MUTEX) .build(); htd = TableDescriptorBuilder .newBuilder(htd) .modifyColumnFamily(hColFamDesc) .build(); admin.modifyTable(htd); } else { LOGGER.debug("SYSTEM MUTEX already appears to exist with the correct TTL, " + "not creating it"); } return true; } ConnectionQueryServicesImpl(QueryServices services, ConnectionInfo connectionInfo, Properties info); @Override Table getTable(byte[] tableName); @Override TableDescriptor getTableDescriptor(byte[] tableName); @Override ReadOnlyProps getProps(); @Override void close(); @Override ConnectionQueryServices getChildQueryServices(ImmutableBytesWritable tenantId); @Override void clearTableRegionCache(TableName tableName); @Override List<HRegionLocation> getAllTableRegions(byte[] tableName); @Override void addTable(PTable table, long resolvedTime); @Override void updateResolvedTimestamp(PTable table, long resolvedTime); @Override void removeTable(PName tenantId, final String tableName, String parentTableName, long tableTimeStamp); @Override void removeColumn(final PName tenantId, final String tableName, final List<PColumn> columnsToRemove, final long tableTimeStamp, final long tableSeqNum, final long resolvedTime); @Override PhoenixConnection connect(String url, Properties info); @Override MetaDataMutationResult createTable(final List<Mutation> tableMetaData, final byte[] physicalTableName,
                                              PTableType tableType, Map<String, Object> tableProps,
                                              final List<Pair<byte[], Map<String, Object>>> families,
                                              byte[][] splits, boolean isNamespaceMapped,
                                              final boolean allocateIndexId, final boolean isDoNotUpgradePropSet,
                                              final PTable parentTable); @Override MetaDataMutationResult getTable(final PName tenantId, final byte[] schemaBytes,
            final byte[] tableBytes, final long tableTimestamp, final long clientTimestamp); @Override MetaDataMutationResult dropTable(final List<Mutation> tableMetaData, final PTableType tableType,
            final boolean cascade); @Override MetaDataMutationResult dropFunction(final List<Mutation> functionData, final boolean ifExists); @Override MetaDataMutationResult addColumn(final List<Mutation> tableMetaData,
                                            PTable table,
                                            final PTable parentTable,
                                            Map<String, List<Pair<String, Object>>> stmtProperties,
                                            Set<String> colFamiliesForPColumnsToBeAdded,
                                            List<PColumn> columns); HashSet<String> existingColumnFamilies(PTable table); static KeepDeletedCells getKeepDeletedCells(PTable table, TableDescriptor tableDesc,
            KeepDeletedCells newKeepDeletedCells); static int getReplicationScope(PTable table, TableDescriptor tableDesc,
            Integer newReplicationScope); static int getTTL(PTable table, TableDescriptor tableDesc, Integer newTTL); @Override MetaDataMutationResult dropColumn(final List<Mutation> tableMetaData,
                                             final PTableType tableType,
                                             final PTable parentTable); @Override void init(final String url, final Properties props); @Override void upgradeSystemTables(final String url, final Properties props); @VisibleForTesting boolean acquireUpgradeMutex(long currentServerSideTableTimestamp); @Override boolean writeMutexCell(String tenantId, String schemaName, String tableName,
            String columnName, String familyName); @VisibleForTesting void releaseUpgradeMutex(); @Override void deleteMutexCell(String tenantId, String schemaName, String tableName,
            String columnName, String familyName); @Override MutationState updateData(MutationPlan plan); @Override int getLowestClusterHBaseVersion(); @Override boolean hasIndexWALCodec(); @Override long clearCache(); @Override Admin getAdmin(); @Override MetaDataMutationResult updateIndexState(final List<Mutation> tableMetaData, String parentTableName); @Override MetaDataMutationResult updateIndexState(final List<Mutation> tableMetaData, String parentTableName, Map<String, List<Pair<String,Object>>> stmtProperties,  PTable table); @Override long createSequence(String tenantId, String schemaName, String sequenceName,
            long startWith, long incrementBy, long cacheSize, long minValue, long maxValue,
            boolean cycle, long timestamp); @Override long dropSequence(String tenantId, String schemaName, String sequenceName, long timestamp); @Override long currentSequenceValue(SequenceKey sequenceKey, long timestamp); @Override void validateSequences(List<SequenceAllocation> sequenceAllocations, long timestamp, long[] values, SQLException[] exceptions, Sequence.ValueOp action); @Override void incrementSequences(List<SequenceAllocation> sequenceAllocations, long timestamp, long[] values, SQLException[] exceptions); @Override void clearTableFromCache(final byte[] tenantId, final byte[] schemaName, final byte[] tableName,
            final long clientTS); @Override void returnSequences(List<SequenceKey> keys, long timestamp, SQLException[] exceptions); @Override void addConnection(PhoenixConnection connection); @Override void removeConnection(PhoenixConnection connection); @Override KeyValueBuilder getKeyValueBuilder(); @Override boolean supportsFeature(Feature feature); @Override String getUserName(); @Override User getUser(); @Override GuidePostsInfo getTableStats(GuidePostsKey key); @Override int getSequenceSaltBuckets(); @Override void addFunction(PFunction function); @Override void removeFunction(PName tenantId, String function, long functionTimeStamp); @Override MetaDataMutationResult getFunctions(PName tenantId, final List<Pair<byte[], Long>> functions,
            final long clientTimestamp); @Override MetaDataMutationResult getSchema(final String schemaName, final long clientTimestamp); @Override MetaDataMutationResult createFunction(final List<Mutation> functionData,
            final PFunction function, final boolean temporary); @Override long getRenewLeaseThresholdMilliSeconds(); @Override boolean isRenewingLeasesEnabled(); @Override HRegionLocation getTableRegionLocation(byte[] tableName, byte[] row); @Override MetaDataMutationResult createSchema(final List<Mutation> schemaMutations, final String schemaName); @Override void addSchema(PSchema schema); @Override void removeSchema(PSchema schema, long schemaTimeStamp); @Override MetaDataMutationResult dropSchema(final List<Mutation> schemaMetaData, final String schemaName); void addTableStats(GuidePostsKey key, GuidePostsInfo info); @Override void invalidateStats(GuidePostsKey key); @Override boolean isUpgradeRequired(); @Override void clearUpgradeRequired(); @Override Configuration getConfiguration(); @Override QueryLoggerDisruptor getQueryDisruptor(); @Override synchronized PhoenixTransactionClient initTransactionClient(Provider provider); @VisibleForTesting List<LinkedBlockingQueue<WeakReference<PhoenixConnection>>> getCachedConnections(); }
ConnectionQueryServicesImpl extends DelegateQueryServices implements ConnectionQueryServices { @VisibleForTesting boolean checkIfSysMutexExistsAndModifyTTLIfRequired(Admin admin) throws IOException { TableDescriptor htd; try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_MUTEX_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored) { try { htd = admin.getDescriptor(TableName.valueOf(SYSTEM_SCHEMA_NAME, SYSTEM_MUTEX_TABLE_NAME)); } catch (org.apache.hadoop.hbase.TableNotFoundException ignored2) { return false; } } if (htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES).getTimeToLive() != TTL_FOR_MUTEX) { LOGGER.debug("SYSTEM MUTEX already appears to exist, but has the wrong TTL. " + "Will modify the TTL"); ColumnFamilyDescriptor hColFamDesc = ColumnFamilyDescriptorBuilder .newBuilder(htd.getColumnFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES)) .setTimeToLive(TTL_FOR_MUTEX) .build(); htd = TableDescriptorBuilder .newBuilder(htd) .modifyColumnFamily(hColFamDesc) .build(); admin.modifyTable(htd); } else { LOGGER.debug("SYSTEM MUTEX already appears to exist with the correct TTL, " + "not creating it"); } return true; } ConnectionQueryServicesImpl(QueryServices services, ConnectionInfo connectionInfo, Properties info); @Override Table getTable(byte[] tableName); @Override TableDescriptor getTableDescriptor(byte[] tableName); @Override ReadOnlyProps getProps(); @Override void close(); @Override ConnectionQueryServices getChildQueryServices(ImmutableBytesWritable tenantId); @Override void clearTableRegionCache(TableName tableName); @Override List<HRegionLocation> getAllTableRegions(byte[] tableName); @Override void addTable(PTable table, long resolvedTime); @Override void updateResolvedTimestamp(PTable table, long resolvedTime); @Override void removeTable(PName tenantId, final String tableName, String parentTableName, long tableTimeStamp); @Override void removeColumn(final PName tenantId, final String tableName, final List<PColumn> columnsToRemove, final long tableTimeStamp, final long tableSeqNum, final long resolvedTime); @Override PhoenixConnection connect(String url, Properties info); @Override MetaDataMutationResult createTable(final List<Mutation> tableMetaData, final byte[] physicalTableName,
                                              PTableType tableType, Map<String, Object> tableProps,
                                              final List<Pair<byte[], Map<String, Object>>> families,
                                              byte[][] splits, boolean isNamespaceMapped,
                                              final boolean allocateIndexId, final boolean isDoNotUpgradePropSet,
                                              final PTable parentTable); @Override MetaDataMutationResult getTable(final PName tenantId, final byte[] schemaBytes,
            final byte[] tableBytes, final long tableTimestamp, final long clientTimestamp); @Override MetaDataMutationResult dropTable(final List<Mutation> tableMetaData, final PTableType tableType,
            final boolean cascade); @Override MetaDataMutationResult dropFunction(final List<Mutation> functionData, final boolean ifExists); @Override MetaDataMutationResult addColumn(final List<Mutation> tableMetaData,
                                            PTable table,
                                            final PTable parentTable,
                                            Map<String, List<Pair<String, Object>>> stmtProperties,
                                            Set<String> colFamiliesForPColumnsToBeAdded,
                                            List<PColumn> columns); HashSet<String> existingColumnFamilies(PTable table); static KeepDeletedCells getKeepDeletedCells(PTable table, TableDescriptor tableDesc,
            KeepDeletedCells newKeepDeletedCells); static int getReplicationScope(PTable table, TableDescriptor tableDesc,
            Integer newReplicationScope); static int getTTL(PTable table, TableDescriptor tableDesc, Integer newTTL); @Override MetaDataMutationResult dropColumn(final List<Mutation> tableMetaData,
                                             final PTableType tableType,
                                             final PTable parentTable); @Override void init(final String url, final Properties props); @Override void upgradeSystemTables(final String url, final Properties props); @VisibleForTesting boolean acquireUpgradeMutex(long currentServerSideTableTimestamp); @Override boolean writeMutexCell(String tenantId, String schemaName, String tableName,
            String columnName, String familyName); @VisibleForTesting void releaseUpgradeMutex(); @Override void deleteMutexCell(String tenantId, String schemaName, String tableName,
            String columnName, String familyName); @Override MutationState updateData(MutationPlan plan); @Override int getLowestClusterHBaseVersion(); @Override boolean hasIndexWALCodec(); @Override long clearCache(); @Override Admin getAdmin(); @Override MetaDataMutationResult updateIndexState(final List<Mutation> tableMetaData, String parentTableName); @Override MetaDataMutationResult updateIndexState(final List<Mutation> tableMetaData, String parentTableName, Map<String, List<Pair<String,Object>>> stmtProperties,  PTable table); @Override long createSequence(String tenantId, String schemaName, String sequenceName,
            long startWith, long incrementBy, long cacheSize, long minValue, long maxValue,
            boolean cycle, long timestamp); @Override long dropSequence(String tenantId, String schemaName, String sequenceName, long timestamp); @Override long currentSequenceValue(SequenceKey sequenceKey, long timestamp); @Override void validateSequences(List<SequenceAllocation> sequenceAllocations, long timestamp, long[] values, SQLException[] exceptions, Sequence.ValueOp action); @Override void incrementSequences(List<SequenceAllocation> sequenceAllocations, long timestamp, long[] values, SQLException[] exceptions); @Override void clearTableFromCache(final byte[] tenantId, final byte[] schemaName, final byte[] tableName,
            final long clientTS); @Override void returnSequences(List<SequenceKey> keys, long timestamp, SQLException[] exceptions); @Override void addConnection(PhoenixConnection connection); @Override void removeConnection(PhoenixConnection connection); @Override KeyValueBuilder getKeyValueBuilder(); @Override boolean supportsFeature(Feature feature); @Override String getUserName(); @Override User getUser(); @Override GuidePostsInfo getTableStats(GuidePostsKey key); @Override int getSequenceSaltBuckets(); @Override void addFunction(PFunction function); @Override void removeFunction(PName tenantId, String function, long functionTimeStamp); @Override MetaDataMutationResult getFunctions(PName tenantId, final List<Pair<byte[], Long>> functions,
            final long clientTimestamp); @Override MetaDataMutationResult getSchema(final String schemaName, final long clientTimestamp); @Override MetaDataMutationResult createFunction(final List<Mutation> functionData,
            final PFunction function, final boolean temporary); @Override long getRenewLeaseThresholdMilliSeconds(); @Override boolean isRenewingLeasesEnabled(); @Override HRegionLocation getTableRegionLocation(byte[] tableName, byte[] row); @Override MetaDataMutationResult createSchema(final List<Mutation> schemaMutations, final String schemaName); @Override void addSchema(PSchema schema); @Override void removeSchema(PSchema schema, long schemaTimeStamp); @Override MetaDataMutationResult dropSchema(final List<Mutation> schemaMetaData, final String schemaName); void addTableStats(GuidePostsKey key, GuidePostsInfo info); @Override void invalidateStats(GuidePostsKey key); @Override boolean isUpgradeRequired(); @Override void clearUpgradeRequired(); @Override Configuration getConfiguration(); @Override QueryLoggerDisruptor getQueryDisruptor(); @Override synchronized PhoenixTransactionClient initTransactionClient(Provider provider); @VisibleForTesting List<LinkedBlockingQueue<WeakReference<PhoenixConnection>>> getCachedConnections(); static final byte[] MUTEX_LOCKED; }