-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function connect by rs list #20
Open
hohice
wants to merge
3
commits into
oceanbase:master
Choose a base branch
from
hohice:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,3 +85,6 @@ test-output | |
# Logs | ||
*.log.* | ||
|
||
# vscode | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,11 +75,23 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle { | |
private AtomicInteger tableEntryRefreshContinuousFailureCount = new AtomicInteger( | ||
0); | ||
private String dataSourceName; | ||
|
||
private String paramURL; | ||
/* | ||
* rsList >> paramURL | ||
*/ | ||
private String rsList; | ||
private Boolean useRsList; | ||
/* | ||
* when use rs list need to asset region | ||
*/ | ||
private String appRegion; | ||
/* | ||
* user name | ||
* Standard format: user@tenant#cluster | ||
* NonStandard format: cluster:tenant:user | ||
* when use rs_list | ||
* Standard format: user@tenant | ||
*/ | ||
private String fullUserName; | ||
private String userName; | ||
|
@@ -293,8 +305,83 @@ private void initProperties() { | |
rpcLoginTimeout = parseToInt(RPC_LOGIN_TIMEOUT.getKey(), rpcLoginTimeout); | ||
} | ||
|
||
private void initMetadataFromRS() throws Exception { | ||
|
||
List<ObServerAddr> rsList = new ArrayList<ObServerAddr>(); | ||
for (String serverStr : getRsList().split(":")){ | ||
ObServerAddr serverAddr = new ObServerAddr(); | ||
serverAddr.setAddress(serverStr); | ||
rsList.add(serverAddr); | ||
} | ||
|
||
List<ObServerAddr> servers = new ArrayList<ObServerAddr>(); | ||
ConcurrentHashMap<ObServerAddr, ObTable> tableRoster = new ConcurrentHashMap<ObServerAddr, ObTable>(); | ||
|
||
TableEntryKey rootServerKey = new TableEntryKey(clusterName, tenantName, | ||
OCEANBASE_DATABASE, ALL_DUMMY_TABLE); | ||
|
||
|
||
TableEntry tableEntry = loadTableEntryRandomly(rsList,// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to reuse the logic below, as the code is mainly the same with the original method. |
||
rootServerKey,// | ||
tableEntryAcquireConnectTimeout,// | ||
tableEntryAcquireSocketTimeout, sysUA); | ||
|
||
List<ReplicaLocation> replicaLocations = tableEntry.getTableLocation() | ||
.getReplicaLocations(); | ||
for (ReplicaLocation replicaLocation : replicaLocations) { | ||
ObServerInfo info = replicaLocation.getInfo(); | ||
ObServerAddr addr = replicaLocation.getAddr(); | ||
if (!info.isActive()) { | ||
logger.warn("will not init location {} because status is {}", addr.toString(), | ||
info.getStatus()); | ||
continue; | ||
} | ||
|
||
// 忽略初始化建连失败,否则client会初始化失败,导致应用无法启动的问题 | ||
// 初始化建连失败(可能性较小),如果后面这台server恢复,数据路由失败,就会重新刷新metadata | ||
// 在失败100次后(RUNTIME_CONTINUOUS_FAILURE_CEILING),重新刷新建连 | ||
// 本地cache 1小时超时后(SERVER_ADDRESS_CACHING_TIMEOUT),重新刷新建连 | ||
// 应急可以直接observer切主 | ||
try { | ||
ObTable obTable = new ObTable.Builder(addr.getIp(), addr.getSvrPort()) // | ||
.setLoginInfo(tenantName, userName, password, database) // | ||
.setProperties(getProperties()).build(); | ||
tableRoster.put(addr, obTable); | ||
servers.add(addr); | ||
} catch (Exception e) { | ||
logger | ||
.warn( | ||
"The addr{}:{} failed to put into table roster, the node status may be wrong, Ignore", | ||
addr.getIp(), addr.getSvrPort()); | ||
} | ||
} | ||
this.tableRoster = tableRoster; | ||
this.serverRoster.reset(servers); | ||
|
||
// Get Server LDC info for weak read consistency. | ||
if (StringUtil.isEmpty(currentIDC)) { | ||
currentIDC = ZoneUtil.getCurrentIDC(); | ||
} | ||
List<ObServerLdcItem> ldcServers = getServerLdc(serverRoster, | ||
tableEntryAcquireConnectTimeout, tableEntryAcquireSocketTimeout, | ||
serverAddressPriorityTimeout, serverAddressCachingTimeout, sysUA); | ||
this.serverRoster.resetServerLdc(ObServerLdcLocation.buildLdcLocation(ldcServers, | ||
currentIDC, getAppRegion())); | ||
|
||
if (logger.isInfoEnabled()) { | ||
logger.info("finish refresh serverRoster: {}", serverRoster); | ||
} | ||
|
||
this.lastRefreshMetadataTimestamp = System.currentTimeMillis(); | ||
} | ||
|
||
private void initMetadata() throws Exception { | ||
|
||
if (getUseRsList().equals(true)){ | ||
initMetadataFromRS(); | ||
return; | ||
} | ||
|
||
this.ocpModel = loadOcpModel(paramURL, dataSourceName, rsListAcquireConnectTimeout, | ||
rsListAcquireReadTimeout, rsListAcquireTryTimes, rsListAcquireRetryInterval); | ||
|
||
|
@@ -529,6 +616,11 @@ public void syncRefreshMetadata() throws Exception { | |
lastRefreshMetadataTimestamp, dataSourceName, paramURL); | ||
} | ||
|
||
if (getUseRsList().equals(true)){ | ||
initMetadataFromRS(); | ||
return; | ||
} | ||
|
||
this.ocpModel = loadOcpModel(paramURL, // | ||
dataSourceName,// | ||
rsListAcquireConnectTimeout,// | ||
|
@@ -1365,6 +1457,59 @@ public String getParamURL() { | |
return paramURL; | ||
} | ||
|
||
/** | ||
* Get param url | ||
* @return param url | ||
*/ | ||
public String getRsList() { | ||
return rsList; | ||
} | ||
|
||
/** | ||
* Get useRsList | ||
* @return useRsList | ||
*/ | ||
public Boolean getUseRsList() { | ||
return useRsList; | ||
} | ||
|
||
/** | ||
* Get param appRegion | ||
* @return param appRegion | ||
*/ | ||
public String getAppRegion() { | ||
return appRegion; | ||
} | ||
|
||
/** | ||
* Set appRegion . | ||
* @param appRegion app region | ||
* @throws IllegalArgumentException if appRegion invalid | ||
*/ | ||
public void setAppRegion(String region) throws IllegalArgumentException{ | ||
if (StringUtils.isBlank(region)) { | ||
throw new IllegalArgumentException(String.format("region is empty, region=%s", region)); | ||
} | ||
this.appRegion = region; | ||
} | ||
|
||
/** | ||
* Set rs list. | ||
* @param rsList rs list | ||
* @throws IllegalArgumentException if rsList invalid | ||
*/ | ||
public void setRsList(String rsList) throws IllegalArgumentException { | ||
if (StringUtils.isBlank(rsList)) { | ||
throw new IllegalArgumentException(String.format("rsList is empty, rsList=%s", rsList)); | ||
} | ||
int paramIndex = rsList.indexOf(':'); | ||
if (-1 == paramIndex || (paramIndex + 1) == paramURL.length()) { | ||
throw new IllegalArgumentException(String.format( | ||
"invalid rs list, parameters are not set. rs_list=%s", rsList)); | ||
} | ||
this.rsList = rsList; | ||
this.useRsList = Boolean.valueOf(true); | ||
} | ||
/** | ||
* Set param url. | ||
* @param paramURL param url | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set port?