diff --git a/cosid-core/src/main/java/me/ahoo/cosid/segment/IdSegmentChain.java b/cosid-core/src/main/java/me/ahoo/cosid/segment/IdSegmentChain.java index 4dbb069b3a..67f14fbfa9 100644 --- a/cosid-core/src/main/java/me/ahoo/cosid/segment/IdSegmentChain.java +++ b/cosid-core/src/main/java/me/ahoo/cosid/segment/IdSegmentChain.java @@ -76,10 +76,7 @@ public long getVersion() { } public int gap(IdSegmentChain end, long step) { - if (this.equals(end)) { - return 0; - } - return (int) ((end.getOffset() - getOffset()) / step); + return (int) ((end.getMaxId() - getSequence()) / step); } public static IdSegmentChain newRoot() { diff --git a/cosid-core/src/main/java/me/ahoo/cosid/segment/SegmentChainId.java b/cosid-core/src/main/java/me/ahoo/cosid/segment/SegmentChainId.java index 9f901ecef6..58f6a84783 100644 --- a/cosid-core/src/main/java/me/ahoo/cosid/segment/SegmentChainId.java +++ b/cosid-core/src/main/java/me/ahoo/cosid/segment/SegmentChainId.java @@ -68,7 +68,7 @@ public IdSegmentChain getHead() { private void forward(IdSegmentChain forwardChain) { if (forwardChain.compareTo(headChain) > 0) { if (log.isDebugEnabled()) { - log.debug("forward - [{}] -> [{}].", headChain, forwardChain); + log.debug("forward - [{}] - [{}] -> [{}].", maxIdDistributor.getNamespacedName(), headChain, forwardChain); } headChain = forwardChain; } @@ -100,12 +100,12 @@ public long generate() { IdSegmentChain nextChain = preIdSegmentChain.getNext(); forward(nextChain); if (log.isDebugEnabled()) { - log.debug("generate - headChain.version:[{}->{}].", preIdSegmentChain.getVersion(), nextChain.getVersion()); + log.debug("generate - [{}] - headChain.version:[{}->{}].", maxIdDistributor.getNamespacedName(),preIdSegmentChain.getVersion(), nextChain.getVersion()); } } } catch (NextIdSegmentExpiredException nextIdSegmentExpiredException) { if (log.isWarnEnabled()) { - log.warn("generate - gave up this next IdSegmentChain.", nextIdSegmentExpiredException); + log.warn("generate - [{}] - gave up this next IdSegmentChain.", maxIdDistributor.getNamespacedName(),nextIdSegmentExpiredException); } } this.prefetchJob.hungry(); @@ -171,11 +171,6 @@ public void run() { public void prefetch() { - if (IdSegmentChain.ROOT_VERSION == tailChain.getVersion()) { - appendChain(tailChain, safeDistance + 1); - return; - } - long wakeupTimeGap = Clock.CACHE.secondTime() - lastHungerTime; final boolean hunger = wakeupTimeGap < hungerThreshold; @@ -183,13 +178,13 @@ public void prefetch() { if (hunger) { this.prefetchDistance = Math.min(Math.multiplyExact(this.prefetchDistance, 2), MAX_PREFETCH_DISTANCE); if (log.isInfoEnabled()) { - log.info("prefetch - {} - Hunger, Safety distance expansion.[{}->{}]", maxIdDistributor.getNamespacedName(), prePrefetchDistance, this.prefetchDistance); + log.info("prefetch - [{}] - Hunger, Safety distance expansion.[{}->{}]", maxIdDistributor.getNamespacedName(), prePrefetchDistance, this.prefetchDistance); } } else { this.prefetchDistance = Math.max(Math.floorDiv(this.prefetchDistance, 2), safeDistance); if (prePrefetchDistance > this.prefetchDistance) { if (log.isInfoEnabled()) { - log.info("prefetch - {} - Full, Safety distance shrinks.[{}->{}]", maxIdDistributor.getNamespacedName(), prePrefetchDistance, this.prefetchDistance); + log.info("prefetch - [{}] - Full, Safety distance shrinks.[{}->{}]", maxIdDistributor.getNamespacedName(), prePrefetchDistance, this.prefetchDistance); } } } @@ -210,7 +205,7 @@ public void prefetch() { if (safeGap <= 0 && !hunger) { if (log.isTraceEnabled()) { - log.trace("prefetch - {} - safeGap is less than or equal to 0, and is not hungry - headChain.version:[{}] - tailChain.version:[{}].", maxIdDistributor.getNamespacedName(), availableHeadChain.getVersion(), tailChain.getVersion()); + log.trace("prefetch - [{}] - safeGap is less than or equal to 0, and is not hungry - headChain.version:[{}] - tailChain.version:[{}].", maxIdDistributor.getNamespacedName(), availableHeadChain.getVersion(), tailChain.getVersion()); } return; } @@ -223,7 +218,7 @@ public void prefetch() { private void appendChain(IdSegmentChain availableHeadChain, int prefetchSegments) { if (log.isDebugEnabled()) { - log.debug("appendChain - {} - headChain.version:[{}] - tailChain.version:[{}] - prefetchSegments:[{}].", maxIdDistributor.getNamespacedName(), availableHeadChain.getVersion(), tailChain.getVersion(), prefetchSegments); + log.debug("appendChain - [{}] - headChain.version:[{}] - tailChain.version:[{}] - prefetchSegments:[{}].", maxIdDistributor.getNamespacedName(), availableHeadChain.getVersion(), tailChain.getVersion(), prefetchSegments); } try { @@ -233,11 +228,11 @@ private void appendChain(IdSegmentChain availableHeadChain, int prefetchSegments tailChain = tailChain.getNext(); } if (log.isDebugEnabled()) { - log.debug("appendChain - {} - restTail - tailChain.version:[{}:{}->{}] .", maxIdDistributor.getNamespacedName(), preTail.gap(tailChain, maxIdDistributor.getStep()), preTail.getVersion(), tailChain.getVersion()); + log.debug("appendChain - [{}] - restTail - tailChain.version:[{}:{}->{}] .", maxIdDistributor.getNamespacedName(), preTail.gap(tailChain, maxIdDistributor.getStep()), preTail.getVersion(), tailChain.getVersion()); } } catch (NextIdSegmentExpiredException nextIdSegmentExpiredException) { if (log.isWarnEnabled()) { - log.warn("appendChain - {} - gave up this next IdSegmentChain.", maxIdDistributor.getNamespacedName(), nextIdSegmentExpiredException); + log.warn("appendChain - [{}] - gave up this next IdSegmentChain.", maxIdDistributor.getNamespacedName(), nextIdSegmentExpiredException); } } } diff --git a/cosid-redis/src/main/java/me/ahoo/cosid/redis/RedisIdSegmentDistributor.java b/cosid-redis/src/main/java/me/ahoo/cosid/redis/RedisIdSegmentDistributor.java index 631d2b7e1e..c2ad0056be 100644 --- a/cosid-redis/src/main/java/me/ahoo/cosid/redis/RedisIdSegmentDistributor.java +++ b/cosid-redis/src/main/java/me/ahoo/cosid/redis/RedisIdSegmentDistributor.java @@ -89,8 +89,8 @@ public long getStep() { public long nextMaxId(long step) { IdSegmentDistributor.ensureStep(step); long maxId = Futures.getUnChecked(fetchMaxIdAsync(step), timeout); - if (log.isInfoEnabled()) { - log.info("nextMaxId - step:[{}] - maxId:[{}].", step, maxId); + if (log.isDebugEnabled()) { + log.debug("nextMaxId - step:[{}] - maxId:[{}].", step, maxId); } return maxId; }