This is an automated email from the ASF dual-hosted git repository. xyuanlu pushed a commit to branch metaclient in repository https://gitbox.apache.org/repos/asf/helix.git
commit 04e2c83404b6c2de44b1906e0e372f640f803315 Author: Marcos Rico Peng <[email protected]> AuthorDate: Mon Mar 6 12:36:29 2023 -0500 TTL Node Interface Methods (#2388) TTL Node Interface Methods Co-authored-by: mapeng <[email protected]> --- .../helix/metaclient/api/MetaClientInterface.java | 47 +++++++++++++++++++++- .../helix/metaclient/impl/zk/ZkMetaClient.java | 10 +++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java b/meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java index e13c61bfb..433184de6 100644 --- a/meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java +++ b/meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java @@ -79,6 +79,14 @@ public interface MetaClientInterface<T> { class Stat { private final int _version; private final EntryMode _entryMode; + // The expiry time of a TTL node in milliseconds. The default is -1 for nodes without expiry time. + private long _expiryTime; + + // The time when the node is created. Measured in milliseconds since the Unix epoch (January 1, 1970, 00:00:00 UTC). + private long _creationTime; + + // The time when the node was las modified. Measured in milliseconds since the Unix epoch when the node was last modified. + private long _modifiedTime; public EntryMode getEntryType() { return _entryMode; @@ -88,9 +96,30 @@ public interface MetaClientInterface<T> { return _version; } + public long getExpiryTime() { + return _expiryTime; + } + + public long getCreationTime() { + return _creationTime; + } + + public long getModifiedTime() { + return _modifiedTime; + } + public Stat (EntryMode mode, int version) { _version = version; _entryMode = mode; + _expiryTime = -1; + } + + public Stat (EntryMode mode, int version, long ctime, long mtime, long etime) { + _version = version; + _entryMode = mode; + _creationTime = ctime; + _modifiedTime = mtime; + _expiryTime = etime; } } @@ -113,7 +142,23 @@ public interface MetaClientInterface<T> { */ void create(final String key, final T data, final EntryMode mode); - // TODO: add TTL create and renew API + /** + * Create an entry of given EntryMode with given key, data, and expiry time (ttl). + * The entry will automatically purge when reached expiry time and has no children. + * The entry will not be created if there is an existing entry with the same key. + * @param key key to identify the entry + * @param data value of the entry + * @param ttl Time-to-live value of the node in milliseconds. + */ + void createWithTTL(final String key, final T data, final long ttl); + + /** + * Renews the specified TTL node adding its original expiry time + * to the current time. Throws an exception if the key is not a valid path + * or isn't of type TTL. + * @param key key to identify the entry + */ + void renewTTLNode(final String key); /** * Set the data for the entry of the given key if it exists and the given version matches the diff --git a/meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java b/meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java index 42acc72c1..7dedd02d5 100644 --- a/meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java +++ b/meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java @@ -88,6 +88,16 @@ public class ZkMetaClient<T> implements MetaClientInterface<T>, AutoCloseable { } } + @Override + public void createWithTTL(String key, T data, long ttl) { + throw new UnsupportedOperationException("TTL nodes aren't yet supported."); + } + + @Override + public void renewTTLNode(String key) { + throw new UnsupportedOperationException("TTL nodes aren't yet supported."); + } + @Override public void set(String key, T data, int version) { try {
