The problem/use-case that the feature addresses
This issue is discuss how to implement link feature on #2668.
Description of the feature
Add the link command, and it has two mode, which is like file systems comamnd ln: - hard link - soft link
The command format like this: link source_key target_key [soft].
Additional information(design principles)
Whether it‘s hard link or soft link, use native data structures whenever possible, and keep the overall logic of the original code.
This design need a new redis object type, we call it OBJECT_TYPE_LINK and a new object encoding OBJECT_ENCODING_POINTER for the hard link. By the new type, linked key will have separate properties(expiration tim, lru, lfu and other).
- The hard link:
-
use the robj pointer and refcount implements the object pointer ; e.g.
o->ptr = sourceValObject; incrRefCount(sourceValObject);...; when lookupKey, we only return o->ptr; -
rdb save only save the new type
RDB_TYPE_LINK_POINTERand the sources_key;
on load data from rdb could use pending list because we not sure whether the key is written, when parsed one db, handle the pending list and reload data to the hash table -
The soft link:
- the object ptr save the source key; like this:
incrRefCount(c->argv[1]); o->ptr = c->argv[1], the c->argv[1] is the key object on parse protocol; - on lookupKey, we need to pay attention to the problem of circular lookup problem; e.g.
a->b, b->c, c->d, d->e, we lookup e, will trigger circular lookup - rdb save and load, only keep the overall logic of the original code and add new branch with the new object type
OBJECT_TYPE_LINK.
Maybe there are other better desings, @madolson please give me some suggestion. Everyone is also welcome to discuss.
Comment From: oranagra
Thank you @kukey for this design and PR. The timing is not great since we're currently busy finalizing RC1 of v7.0, so i'm afraid we can't spare time to look deeply, and i'm not sure if we could later add such a new concept after RC1, and it may have to wait for 7.2 or alike.
Without diving into the details, i can share few random points: * i fear it is not a simple as it looks, and there are many corner cases to handle. * redis 7.0 comes with a new scripting feature (#9780) which could solve some of the use cases of this feature (instead of a schema and links, users can change their apps to use a high level logical set of operations they code into the server). * the one thing that Functions don't solve though is eviction / expiration, so the links feature may still be handy.
p.s. IMHO the only reason to open an issue is when don't have code to post yet (lots of coding effort, or decisions to be made). since you have a PR ready, the discussion could have been made there.
Comment From: kukey
@oranagra OK, thanks for your suggestion