in mode/cluster/repository/consul/src/main/java/org/apache/shardingsphere/mode/repository/cluster/consul/lock/ConsulDistributedLock.java [108:134]
private long waitUntilRelease(final long valueIndex, final long timeoutMillis) {
long currentIndex = valueIndex < 0 ? 0 : valueIndex;
long spentMillis = 0L;
long timeoutTime = System.currentTimeMillis() + timeoutMillis;
long remainingMillis = timeoutMillis;
while (true) {
long startTime = System.currentTimeMillis();
if (startTime >= timeoutTime) {
return timeoutMillis;
}
Response<GetValue> response = getResponse(
((ShardingSphereConsulClient) client).getRawClient().makeGetRequest(String.format("/v1/kv/%s", lockPath), null, new ShardingSphereQueryParams(remainingMillis, currentIndex)));
spentMillis += System.currentTimeMillis() - startTime;
remainingMillis -= spentMillis;
Long index = response.getConsulIndex();
if (null != index && index >= currentIndex) {
if (0 != currentIndex && (null == response.getValue() || null == response.getValue().getValue() || lockPath.equals(response.getValue().getKey()))) {
return spentMillis;
}
currentIndex = index;
continue;
}
if (null != index) {
currentIndex = 0;
}
}
}