use of com.ctrip.framework.dal.cluster.client.database.Database in project dal by ctripcorp.
the class ClusterDatabaseSet method getSlaveDbs.
@Override
public List<DataBase> getSlaveDbs(String shard) {
List<Database> clusterDatabases = cluster.getSlavesOnShard(getDbShardIndex(shard));
List<DataBase> dataBases = new LinkedList<>();
for (Database clusterDatabase : clusterDatabases) {
dataBases.add(new ClusterDataBase(clusterDatabase));
}
return dataBases;
}
use of com.ctrip.framework.dal.cluster.client.database.Database in project dal by ctripcorp.
the class ClusterDynamicDataSource method createCustomDataSource.
protected DataSource createCustomDataSource() {
CustomDataSourceFactory dataSourceFactory = getCustomDataSourceFactory();
List<Database> databases = cluster.getDatabases();
Set<HostSpec> hostsInfos = new HashSet<>();
databases.forEach(database -> {
ConnectionString connString = database.getConnectionString();
HostSpec host = HostSpec.of(connString.getPrimaryHost(), connString.getPrimaryPort(), database.getZone());
hostsInfos.add(host);
});
return dataSourceFactory.createDataSource(hostsInfos, getProperties(databases.get(0)));
}
use of com.ctrip.framework.dal.cluster.client.database.Database in project dal by ctripcorp.
the class DatabaseShardImpl method initReadStrategy.
public void initReadStrategy() {
ClusterRouteStrategyConfig config = databaseShardConfig.getClusterConfig().getRouteStrategyConfig();
if (config == null || config.multiMaster()) {
return;
}
routeStrategy = (ReadStrategy) config.generate();
List<Database> databases = new ArrayList<>();
databases.addAll(masters);
databases.addAll(slaves);
Set<HostSpec> hostSpecs = new HashSet<>();
databases.forEach(database -> {
ConnectionString connString = database.getConnectionString();
HostSpec host = HostSpec.of(connString.getPrimaryHost(), connString.getPrimaryPort(), database.getZone(), database.isMaster());
hostToDataBase.putIfAbsent(host, database);
hostSpecs.add(host);
});
try {
routeStrategy.init(hostSpecs, new CaseInsensitiveProperties());
} catch (DalMetadataException error) {
throw new DalMetadataException(databaseShardConfig.getClusterConfig().getClusterName() + error.getMessage());
}
}
use of com.ctrip.framework.dal.cluster.client.database.Database in project dal by ctripcorp.
the class GroupDataSource method createReadDataSource.
protected void createReadDataSource() {
int slaveIndex = 0;
for (Database database : cluster.getSlavesOnShard(clusterInfo.getShardIndex())) {
ClusterInfo slaveClusterInfo = clusterInfo.cloneSlaveWithIndex(slaveIndex);
readDataSource.put(database, locator.getDataSource(slaveClusterInfo));
slaveIndex++;
}
readDataSource.put(cluster.getMasterOnShard(clusterInfo.getShardIndex()), createWriteDataSource());
}
Aggregations