Skip to content

Conversation

yezhizi
Copy link
Contributor

@yezhizi yezhizi commented Sep 7, 2025

Part of #3048
Add a new CF for label-based indexing. The key format is as following:

+-----------+--------------+----------------+------------+------------------+--------------+---------+
|     ns    |  index_type  | label_key_size |  label_key | label_value_size |  label_value |  key    | => null
| (1+Xbytes)|    (1byte)   |    (4byte)     |   (Ybyte)  |   (4byte)        |   (Zbyte)    | (Kbyte) |
+-----------+--------------+----------------+------------+------------------+--------------+---------+
enum index_type
0 TS_LABEL

Now we can do:

127.0.0.1:6666> TS.CREATE temp:TLV LABELS type temp location TLV
127.0.0.1:6666> TS.CREATE temp:JLM LABELS type temp location JLM
127.0.0.1:6666> TS.MADD temp:TLV 1000 30 temp:TLV 1010 35 temp:TLV 1020 9999 temp:TLV 1030 40
127.0.0.1:6666> TS.MADD temp:JLM 1005 30 temp:JLM 1015 35 temp:JLM 1025 9999 temp:JLM 1035 40
127.0.0.1:6666> TS.MGET WITHLABELS FILTER type=temp
1) 1) "temp:JLM"
   2) 1) 1) "location"
         2) "JLM"
      2) 1) "type"
         2) "temp"
   3) 1) 1) (integer) 1035
         2) (double) 40
2) 1) "temp:TLV"
   2) 1) 1) "location"
         2) "TLV"
      2) 1) "type"
         2) "temp"
   3) 1) 1) (integer) 1030
         2) (double) 40
127.0.0.1:6666> TS.MGET SELECTED_LABELS location FILTER type=temp
1) 1) "temp:JLM"
   2) 1) 1) "location"
         2) "JLM"
   3) 1) 1) (integer) 1035
         2) (double) 40
2) 1) "temp:TLV"
   2) 1) 1) "location"
         2) "TLV"
   3) 1) 1) (integer) 1030
         2) (double) 40

@yezhizi yezhizi requested a review from PragmaTwice September 8, 2025 02:35
PragmaTwice
PragmaTwice previously approved these changes Sep 8, 2025
@PragmaTwice PragmaTwice changed the title feat(ts): Add label-based indexing support and TS.MEGT command feat(ts): Add label-based indexing support and TS.MGET command Sep 8, 2025
@yezhizi
Copy link
Contributor Author

yezhizi commented Sep 8, 2025

@PragmaTwice Could you tell me how to fix this test error? I don't really understand why it failed.

/Users/runner/work/kvrocks/kvrocks/tests/cppunit/compact_test.cc:196: Failure
Value of: sg.IsNotFound()
  Actual: false
Expected: true

[  FAILED  ] 1 test, listed below:
[  FAILED  ] Compact.SearchFilter

@yezhizi yezhizi requested a review from PragmaTwice September 8, 2025 14:52
@yezhizi yezhizi requested a review from PragmaTwice September 9, 2025 03:47
@PragmaTwice
Copy link
Member

PragmaTwice commented Sep 9, 2025

@yezhizi Not necessary in this PR, but we need to consider:

  • if a TS key is deleted, how to also delete related label index?
  • if a TS key is expired, how to handle it in the compaction filter of the new CF?

Maybe when we are accessing the label index, we should check if the TS key is currently available (not expired or deleted), and in compaction we can recycle label index with expired/deleted TS keys.

@PragmaTwice PragmaTwice enabled auto-merge (squash) September 9, 2025 10:55
@PragmaTwice PragmaTwice disabled auto-merge September 9, 2025 10:55
@PragmaTwice PragmaTwice enabled auto-merge (squash) September 9, 2025 10:55
@PragmaTwice PragmaTwice merged commit cf28ab1 into apache:unstable Sep 9, 2025
67 of 69 checks passed
Copy link

sonarqubecloud bot commented Sep 9, 2025

@yezhizi
Copy link
Contributor Author

yezhizi commented Sep 9, 2025

Okay, I’ll try to improve on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants