-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keeper support fsync with rordb (#772)
Co-authored-by: lishanglin <[email protected]>
- Loading branch information
1 parent
aa41c04
commit fe23abd
Showing
93 changed files
with
1,641 additions
and
678 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
core/src/main/java/com/ctrip/xpipe/cache/TimeBoundCache.java
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.ctrip.xpipe.cache; | ||
|
||
import java.util.function.LongSupplier; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* @author lishanglin | ||
* date 2021/4/17 | ||
*/ | ||
public class TimeBoundCache<T> { | ||
|
||
private T data; | ||
|
||
private long lastRefreshAt; | ||
|
||
private long expiredAt; | ||
|
||
private LongSupplier timeoutMillSupplier; | ||
|
||
private Supplier<T> dataSupplier; | ||
|
||
public TimeBoundCache(LongSupplier timeoutMillSupplier, Supplier<T> dataSupplier) { | ||
this.data = null; | ||
this.expiredAt = 0L; | ||
this.lastRefreshAt = 0L; | ||
this.timeoutMillSupplier = timeoutMillSupplier; | ||
this.dataSupplier = dataSupplier; | ||
} | ||
|
||
// allow data timeout | ||
public T getCurrentData() { | ||
return this.data; | ||
} | ||
|
||
public T getData() { | ||
return getData(false); | ||
} | ||
|
||
public T getData(boolean disableCache) { | ||
long current = System.currentTimeMillis(); | ||
if (current < lastRefreshAt) { | ||
// system time roll back | ||
resetExpireAt(); | ||
} | ||
|
||
if (!disableCache && null != data && expiredAt > current) { | ||
return data; | ||
} | ||
|
||
synchronized (this) { | ||
if (!disableCache && null != data && expiredAt > current) return data; | ||
data = dataSupplier.get(); | ||
refreshExpireAt(); | ||
return data; | ||
} | ||
} | ||
|
||
public synchronized void refresh() { | ||
this.data = dataSupplier.get(); | ||
refreshExpireAt(); | ||
} | ||
|
||
private void resetExpireAt() { | ||
this.lastRefreshAt = 0L; | ||
this.expiredAt = 0L; | ||
} | ||
|
||
private void refreshExpireAt() { | ||
long timeout = timeoutMillSupplier.getAsLong(); | ||
this.lastRefreshAt = System.currentTimeMillis(); | ||
this.expiredAt = lastRefreshAt + timeout; | ||
// expiredAt exceeds max long | ||
if (this.expiredAt < timeout) this.expiredAt = Long.MAX_VALUE; | ||
} | ||
|
||
} |
1 change: 0 additions & 1 deletion
1
core/src/main/java/com/ctrip/xpipe/payload/ByteArrayOutputStreamPayload.java
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
57 changes: 0 additions & 57 deletions
57
redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/cache/TimeBoundCache.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
redis/redis-console/src/main/java/com/ctrip/xpipe/redis/console/cache/impl/DcCacheImpl.java
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
2 changes: 1 addition & 1 deletion
2
.../src/main/java/com/ctrip/xpipe/redis/console/controller/api/migrate/MigrationInfoApi.java
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
2 changes: 1 addition & 1 deletion
2
...nsole/src/main/java/com/ctrip/xpipe/redis/console/resources/AbstractPersistenceCache.java
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
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
2 changes: 1 addition & 1 deletion
2
.../main/java/com/ctrip/xpipe/redis/console/sentinel/impl/DefaultSentinelBalanceService.java
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 |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
public enum CAPA { | ||
|
||
EOF, | ||
PSYNC2; | ||
PSYNC2, | ||
RORDB; | ||
|
||
public static CAPA of(String capaString) { | ||
|
||
|
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
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
Oops, something went wrong.