DiceDB / dice

DiceDB is an in-memory, real-time, and reactive database with Redis and SQL support optimized for modern hardware and building real-time applications.
https://dicedb.io/
Other
5.57k stars 805 forks source link

Inconsistent `OBJECT`: Subcommands are not executing as expected #934

Open sashpawar11 opened 10 hours ago

sashpawar11 commented 10 hours ago

Steps to reproduce

  1. SETa key with a value
  2. Execute a GET command on the key
  3. Execute the OBJECT command with all the supported sub-commands ( ENCODING, REFCOUNT, FREQ, IDLETIME )

Expected output

The expected output when the above set of commands (maybe when run on Redis)

  1. OBJECT ENCODING <key>
Returns the internal encoding for the  object stored at <key> : eg - raw, embstr, etc.
  1. OBJECT FREQ <key>
If LRU policy exists , redis returns the access frequency of a key, if the LFU (Least Frequently Used) eviction policy is enabled.
If LRU policy does not exist , redis returns the following message:

(error) ERR An LFU maxmemory policy is not selected, access frequency not tracked. Please note that when switching between policies at runtime LRU and LFU data will take some time to adjust.
  1. OBJECT REFCOUNT <key>
Returns the number of references of the value associated with the specified key.

Observed output

The observed output when the above set of commands when run on DiceDB

  1. OBJECT ENCODING <key>
    
    127.0.0.1:7379> OBJECT ENCODING mykey
    (error) ERROR syntax error

2. `OBJECT FREQ <key>`

127.0.0.1:7379> OBJECT FREQ mykey (error) ERROR syntax error


3. `OBJECT REFCOUNT <key>`

127.0.0.1:7379> OBJECT REFCOUNT mykey (error) ERROR syntax error



## Expectations for resolution

This issue will be considered resolved when the following things are done

1. changes in the [`dice`](https://github.com/dicedb/dice) code to meet the expected behavior
3. addition of relevant test case to ensure we catch the regression

You can find the tests under the `integration_tests` directory of the [`dice`](https://github.com/dicedb/dice) repository and the steps to run are in the [README file](https://github.com/dicedb/dice). Refer to the following links to set up DiceDB and Redis 7.2.5 locally

- [setup DiceDB locally](https://github.com/dicedb/dice)
- [setup Redis 7.2.5 locally](https://gist.github.com/arpitbbhayani/94aedf279349303ed7394197976b6843)
- [setup DiceDB CLI](https://github.com/dicedb/dice)
RishabhC-137 commented 10 hours ago

Can I take this ? @sashpawar11

sashpawar11 commented 10 hours ago

Hi @lucifercr07 @apoorvyadav1111 - Please review, and assign to me if the errors are legit. Encountered while auditing the doc on #834

sashpawar11 commented 10 hours ago

Root cause identified : We currently only support evalObjectIdleTime as a case in evalOBJECT.

Will add support for the other subcomands under this issue.

sashpawar11 commented 9 hours ago

Hi @lucifercr07 @apoorvyadav1111 - per redis docs and codebase, the following encoding types are defined and their logic built:

#define OBJ_ENCODING_RAW 0     /* Raw representation */
#define OBJ_ENCODING_INT 1     /* Encoded as integer */
#define OBJ_ENCODING_HT 2      /* Encoded as hash table */
#define OBJ_ENCODING_ZIPMAP 3  /* No longer used: old hash encoding. */
#define OBJ_ENCODING_LINKEDLIST 4 /* No longer used: old list encoding. */
#define OBJ_ENCODING_ZIPLIST 5 /* No longer used: old list/hash/zset encoding. */
#define OBJ_ENCODING_INTSET 6  /* Encoded as intset */
#define OBJ_ENCODING_SKIPLIST 7  /* Encoded as skiplist */
#define OBJ_ENCODING_EMBSTR 8  /* Embedded sds string encoding */
#define OBJ_ENCODING_QUICKLIST 9 /* Encoded as linked list of listpacks */
#define OBJ_ENCODING_STREAM 10 /* Encoded as a radix tree of listpacks */
#define OBJ_ENCODING_LISTPACK 11 /* Encoded as a listpack */
#define OBJ_ENCODING_LISTPACK_EX 12 /* Encoded as listpack, extended with metadata */

We are missing many of these in our codebase and their related logic > object.go, and also have some additional encoding types in their place.

Please advise if I should implement the command with whatever dice supports currently, ensuring that the OBJECT ENCODING <key>command will return currently supported encoding types from dice?

sashpawar11 commented 1 hour ago

Got clarification on the above on today's community call -> we will return what is supported in dice.