下面列出了org.apache.hadoop.hbase.client.Connection#getConfiguration ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void restoreFromSnapshot(Connection conn) throws IOException {
Configuration conf = conn.getConfiguration();
LOG.debug("Restoring " + BackupSystemTable.getTableNameAsString(conf) + " from snapshot");
try (Admin admin = conn.getAdmin()) {
String snapshotName = BackupSystemTable.getSnapshotName(conf);
if (snapshotExists(admin, snapshotName)) {
admin.disableTable(BackupSystemTable.getTableName(conf));
admin.restoreSnapshot(snapshotName);
admin.enableTable(BackupSystemTable.getTableName(conf));
LOG.debug("Done restoring backup system table");
} else {
// Snapshot does not exists, i.e completeBackup failed after
// deleting backup system table snapshot
// In this case we log WARN and proceed
LOG.warn(
"Could not restore backup system table. Snapshot " + snapshotName + " does not exists.");
}
}
}
public void init(final Connection conn, final String backupId, BackupRequest request)
throws IOException {
if (request.getBackupType() == BackupType.FULL) {
backupManager = new BackupManager(conn, conn.getConfiguration());
} else {
backupManager = new IncrementalBackupManager(conn, conn.getConfiguration());
}
this.backupId = backupId;
this.tableList = request.getTableList();
this.conn = conn;
this.conf = conn.getConfiguration();
this.fs = CommonFSUtils.getCurrentFileSystem(conf);
backupInfo =
backupManager.createBackupInfo(backupId, request.getBackupType(), tableList,
request.getTargetRootDir(), request.getTotalTasks(), request.getBandwidth());
if (tableList == null || tableList.isEmpty()) {
this.tableList = new ArrayList<>(backupInfo.getTables());
}
// Start new session
backupManager.startBackupSession();
}
public static TableBackupClient create(Connection conn, String backupId, BackupRequest request)
throws IOException {
Configuration conf = conn.getConfiguration();
try {
String clsName = conf.get(TableBackupClient.BACKUP_CLIENT_IMPL_CLASS);
if (clsName != null) {
Class<? extends TableBackupClient> clientImpl;
clientImpl = Class.forName(clsName).asSubclass(TableBackupClient.class);
TableBackupClient client = clientImpl.getDeclaredConstructor().newInstance();
client.init(conn, backupId, request);
return client;
}
} catch (Exception e) {
throw new IOException(e);
}
BackupType type = request.getBackupType();
if (type == BackupType.FULL) {
return new FullTableBackupClient(conn, backupId, request);
} else {
return new IncrementalTableBackupClient(conn, backupId, request);
}
}
public RegionMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,
Sink sink, ExecutorService executor, boolean writeSniffing, TableName writeTableName,
boolean treatFailureAsError, HashMap<String, Long> configuredReadTableTimeouts,
long configuredWriteTableTimeout,
long allowedFailures) {
super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError,
allowedFailures);
Configuration conf = connection.getConfiguration();
this.writeSniffing = writeSniffing;
this.writeTableName = writeTableName;
this.writeDataTTL =
conf.getInt(HConstants.HBASE_CANARY_WRITE_DATA_TTL_KEY, DEFAULT_WRITE_DATA_TTL);
this.regionsLowerLimit =
conf.getFloat(HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_LOWERLIMIT_KEY, 1.0f);
this.regionsUpperLimit =
conf.getFloat(HConstants.HBASE_CANARY_WRITE_PERSERVER_REGIONS_UPPERLIMIT_KEY, 1.5f);
this.checkPeriod =
conf.getInt(HConstants.HBASE_CANARY_WRITE_TABLE_CHECK_PERIOD_KEY,
DEFAULT_WRITE_TABLE_CHECK_PERIOD);
this.rawScanEnabled = conf.getBoolean(HConstants.HBASE_CANARY_READ_RAW_SCAN_KEY, false);
this.configuredReadTableTimeouts = new HashMap<>(configuredReadTableTimeouts);
this.configuredWriteTableTimeout = configuredWriteTableTimeout;
this.readAllCF = conf.getBoolean(HConstants.HBASE_CANARY_READ_ALL_CF, true);
}
protected ZookeeperMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,
Sink sink, ExecutorService executor, boolean treatFailureAsError, long allowedFailures) {
super(connection, monitorTargets, useRegExp,
sink, executor, treatFailureAsError, allowedFailures);
Configuration configuration = connection.getConfiguration();
znode =
configuration.get(ZOOKEEPER_ZNODE_PARENT,
DEFAULT_ZOOKEEPER_ZNODE_PARENT);
timeout = configuration
.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);
ConnectStringParser parser =
new ConnectStringParser(ZKConfig.getZKQuorumServersString(configuration));
hosts = Lists.newArrayList();
for (InetSocketAddress server : parser.getServerAddresses()) {
hosts.add(server.toString());
}
if (allowedFailures > (hosts.size() - 1) / 2) {
LOG.warn(
"Confirm allowable number of failed ZooKeeper nodes, as quorum will "
+ "already be lost. Setting of {} failures is unexpected for {} ensemble size.",
allowedFailures, hosts.size());
}
}
public static void deleteSnapshot(Connection conn) throws IOException {
Configuration conf = conn.getConfiguration();
LOG.debug("Deleting " + BackupSystemTable.getSnapshotName(conf) + " from the system");
try (Admin admin = conn.getAdmin()) {
String snapshotName = BackupSystemTable.getSnapshotName(conf);
if (snapshotExists(admin, snapshotName)) {
admin.deleteSnapshot(snapshotName);
LOG.debug("Done deleting backup system table snapshot");
} else {
LOG.error("Snapshot " + snapshotName + " does not exists");
}
}
}
public RestoreTablesClient(Connection conn, RestoreRequest request) {
this.targetRootDir = request.getBackupRootDir();
this.backupId = request.getBackupId();
this.sTableArray = request.getFromTables();
this.tTableArray = request.getToTables();
if (tTableArray == null || tTableArray.length == 0) {
this.tTableArray = sTableArray;
}
this.isOverwrite = request.isOverwrite();
this.conn = conn;
this.conf = conn.getConfiguration();
}
public static void snapshot(Connection conn) throws IOException {
try (Admin admin = conn.getAdmin()) {
Configuration conf = conn.getConfiguration();
admin.snapshot(BackupSystemTable.getSnapshotName(conf), BackupSystemTable.getTableName(conf));
}
}
Test(final Connection con, final TestOptions options, final Status status) {
super(con == null ? HBaseConfiguration.create() : con.getConfiguration(), options, status);
this.connection = con;
}
@Test
public void testRebuildIndexConnectionProperties() throws Exception {
try (PhoenixConnection rebuildIndexConnection =
MetaDataRegionObserver.getRebuildIndexConnection(hbaseTestUtil.getMiniHBaseCluster().getConfiguration())) {
try (PhoenixConnection regularConnection =
DriverManager.getConnection(url).unwrap(PhoenixConnection.class)) {
String rebuildUrl = rebuildIndexConnection.getURL();
// assert that we are working with non-test urls
assertFalse(PhoenixEmbeddedDriver.isTestUrl(url));
assertFalse(PhoenixEmbeddedDriver.isTestUrl(rebuildUrl));
// assert that the url ends with expected string
assertTrue(
rebuildUrl.contains(MetaDataRegionObserver.REBUILD_INDEX_APPEND_TO_URL_STRING));
// assert that the url for regular connection vs the rebuild connection is different
assertFalse(rebuildUrl.equals(regularConnection.getURL()));
Configuration rebuildQueryServicesConfig =
rebuildIndexConnection.getQueryServices().getConfiguration();
// assert that the properties are part of the query services config
assertEquals(
Long.toString(QueryServicesOptions.DEFAULT_INDEX_REBUILD_QUERY_TIMEOUT),
rebuildQueryServicesConfig.get(QueryServices.THREAD_TIMEOUT_MS_ATTRIB));
assertEquals(
Long.toString(
QueryServicesOptions.DEFAULT_INDEX_REBUILD_CLIENT_SCANNER_TIMEOUT),
rebuildQueryServicesConfig.get(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD));
assertEquals(Long.toString(QueryServicesOptions.DEFAULT_INDEX_REBUILD_RPC_TIMEOUT),
rebuildQueryServicesConfig.get(HConstants.HBASE_RPC_TIMEOUT_KEY));
assertEquals(
Long.toString(NUM_RPC_RETRIES),
rebuildQueryServicesConfig.get(HConstants.HBASE_CLIENT_RETRIES_NUMBER));
ConnectionQueryServices rebuildQueryServices = rebuildIndexConnection.getQueryServices();
Connection rebuildIndexHConnection =
(Connection) Whitebox.getInternalState(rebuildQueryServices,
"connection");
Connection regularHConnection =
(Connection) Whitebox.getInternalState(
regularConnection.getQueryServices(), "connection");
// assert that a new HConnection was created
assertFalse(
regularHConnection.toString().equals(rebuildIndexHConnection.toString()));
Configuration rebuildHConnectionConfig = rebuildIndexHConnection.getConfiguration();
// assert that the HConnection has the desired properties needed for rebuilding
// indices
assertEquals(
Long.toString(
QueryServicesOptions.DEFAULT_INDEX_REBUILD_CLIENT_SCANNER_TIMEOUT),
rebuildHConnectionConfig.get(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD));
assertEquals(Long.toString(QueryServicesOptions.DEFAULT_INDEX_REBUILD_RPC_TIMEOUT),
rebuildHConnectionConfig.get(HConstants.HBASE_RPC_TIMEOUT_KEY));
assertEquals(
Long.toString(NUM_RPC_RETRIES),
rebuildHConnectionConfig.get(HConstants.HBASE_CLIENT_RETRIES_NUMBER));
}
}
}