Skip to content

Commit

Permalink
Merge pull request #890 from wangqifan/bugfix/add_version_meta
Browse files Browse the repository at this point in the history
add version for xpipemeta
  • Loading branch information
LanternLee authored Sep 26, 2024
2 parents 6ee6827 + dff41e6 commit a181ca9
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public XpipeMeta getXpipeMeta() {
}

@Override
public XpipeMeta getXpipeMetaLongPull(long updateTime) throws InterruptedException {
public XpipeMeta getXpipeMetaLongPull(long version) throws InterruptedException {
return null;
}

Expand Down Expand Up @@ -167,6 +167,11 @@ public long getLastUpdateTime() {
return 0;
}

@Override
public long getVersion() {
return xpipeMeta.getVersion();
}

@Override
public ClusterType getClusterType(String clusterId) {
return ClusterType.ONE_WAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ public String getDividedMeta(@RequestParam(value="format", required = false) Str

@GetMapping(ConsoleCheckerPath.PATH_GET_ALL_META_LONG_PULL)
public DeferredResult<String> getDividedMetaLongPull(@RequestParam(value="format", required = false) String format,
@RequestParam(value="updateTime") long updateTime) {
@RequestParam(value="version") long version) {
DeferredResult<String> response = new DeferredResult<>(Long.valueOf(consoleConfig.getServletMethodTimeoutMilli()));

executors.execute(new Runnable() {
@Override
public void run() {
try {
XpipeMeta xpipeMeta = metaCache.getXpipeMetaLongPull(updateTime);
XpipeMeta xpipeMeta = metaCache.getXpipeMetaLongPull(version);
response.setResult((format != null && format.equals("xml"))? xpipeMeta.toString() : coder.encode(xpipeMeta));
} catch (InterruptedException e) {
response.setErrorResult(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected void refreshMeta(XpipeMeta xpipeMeta) {
monitor2ClusterShard = Maps.newHashMap();
allKeeperSize = allKeepers == null ? DEFAULT_KEEPER_NUMBERS : allKeepers.size();
allKeepers = null;
lastUpdateTime = System.currentTimeMillis();
}

protected XpipeMeta createXpipeMeta(List<DcMeta> dcMetas, List<RedisCheckRuleMeta> redisCheckRuleMetas){
Expand All @@ -103,15 +104,12 @@ protected XpipeMeta createXpipeMeta(List<DcMeta> dcMetas, List<RedisCheckRuleMet
for(RedisCheckRuleMeta redisCheckRuleMeta : redisCheckRuleMetas) {
xpipeMeta.addRedisCheckRule(redisCheckRuleMeta);
}

xpipeMeta.setUpdateTime(System.currentTimeMillis());

xpipeMeta.setVersion(System.currentTimeMillis());
return xpipeMeta;

}

@Override
public XpipeMeta getXpipeMetaLongPull(long updateTime) throws InterruptedException {
public XpipeMeta getXpipeMetaLongPull(long version) throws InterruptedException {
return null;
}

Expand Down Expand Up @@ -308,8 +306,13 @@ public ClusterType getAzGroupType(HostPort hostPort) {

@Override
public long getLastUpdateTime() {
return lastUpdateTime;
}

@Override
public long getVersion() {
if(getXpipeMeta() != null) {
return getXpipeMeta().getUpdateTime();
return getXpipeMeta().getVersion();
} else {
return 0l;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void loadCache() throws Exception {
@Override
public void go() {
try {
XpipeMeta xpipeMeta = consolePortalService.getXpipeAllMeta(getLastUpdateTime());
XpipeMeta xpipeMeta = consolePortalService.getXpipeAllMeta(getVersion());
checkMeta(xpipeMeta, config.maxRemovedDcsCnt(), config.maxRemovedClustersPercent());
refreshMetaParts();
refreshMeta(xpipeMeta);
Expand All @@ -50,9 +50,9 @@ public void startLoadMeta() {

logger.info("[loadMeta][start]{}", this);

long refreshIntervalMilli = 500;
long refreshIntervalMilli = config.getCacheRefreshInterval();

future = scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {
future = scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {
@Override
protected void doRun() throws Exception {
if(!taskTrigger.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public List<ProxyModel> getMonitorActiveProxiesByDc() {
return resp.getBody();
}

public XpipeMeta getXpipeAllMeta(long updateTime) throws SAXException, IOException {
public XpipeMeta getXpipeAllMeta(long version) throws SAXException, IOException {
UriComponents comp = UriComponentsBuilder.fromHttpUrl(config.getConsoleNoDbDomain() + ConsoleCheckerPath.PATH_GET_ALL_META_LONG_PULL)
.queryParam("format", "xml")
.queryParam("updateTime", updateTime)
.queryParam("version", version)
.build();

ResponseEntity<String> raw = exchange(comp.toUri().toString(), HttpMethod.GET, null, String.class, "getXpipeAllMeta");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public void notLeader() {
}

@Override
public XpipeMeta getXpipeMetaLongPull(long updateTime) throws InterruptedException {
public XpipeMeta getXpipeMetaLongPull(long version) throws InterruptedException {
XpipeMeta xpipeMeta = null;
if(lock.tryLock(consoleConfig.getCacheRefreshInterval(), TimeUnit.MILLISECONDS)) {
try {
if(getLastUpdateTime() <= updateTime) {
if(getVersion() <= version) {
condition.await(consoleConfig.getCacheRefreshInterval(), TimeUnit.MILLISECONDS);
}
xpipeMeta = meta.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface MetaCache {

XpipeMeta getXpipeMeta();

XpipeMeta getXpipeMetaLongPull(long updateTime) throws InterruptedException;
XpipeMeta getXpipeMetaLongPull(long version) throws InterruptedException;

XpipeMeta getDividedXpipeMeta(int partIndex);

Expand Down Expand Up @@ -85,6 +85,8 @@ public interface MetaCache {

long getLastUpdateTime();

long getVersion();

ClusterType getClusterType(String clusterId);

boolean isMetaChain(HostPort src, HostPort dst);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<entity name="xpipe" root="true">
<entity-ref name="redisCheckRule" type="list" names="redisCheckRules" />
<entity-ref name="dc" type="list" names="dcs" />
<attribute name="updateTime" value-type="Long" />
<attribute name="version" value-type="Long" />
</entity>
<entity name="redisCheckRule">
<attribute name="id" value-type="long" />
Expand Down

0 comments on commit a181ca9

Please sign in to comment.