You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "PragmaTwice (via GitHub)" <gi...@apache.org> on 2024/01/28 09:49:23 UTC

[PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

PragmaTwice opened a new pull request, #2066:
URL: https://github.com/apache/kvrocks/pull/2066

   It close #2065.
   
   The current encoding design:
   ```
   search data type metadata:
   
   key (index name) -> flag | expire | version | size | on_data_type (HASH or JSON)
   
   prefixes encoding:
   
   key (index name) | PREFIXES -> prefix1 prefix2 ...
   
   tag field metadata encoding:
   
   key (index name) | TAG_FIELD_META | field name -> separator | case sensitive
   
   tag field index encoding:
   
   key (index name) | TAG_FIELD | field name | tag | key -> (nil)
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#issuecomment-1913611965

   > How can we list all indexes efficiently? 🤔 RediSearch seems would tracking the records for insert and maintaining index on that, should we support some global tracking structure?
   
   Like RediSearch, we will track all HASH and JSON commands and adjust our indexes accordingly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#discussion_r1468826283


##########
src/types/redis_search_encoding.h:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#pragma once
+
+#include <encoding.h>
+#include <storage/redis_metadata.h>
+
+namespace redis {
+
+inline constexpr auto kErrorInsufficientLength = "insufficient length while decoding metadata";
+
+enum class SearchSubkeyType : uint8_t {

Review Comment:
   `TAG_FIELD_META` means metadata of this index (field, typed `tag`), and `TAG_FIELD` simply stores the index.
   
   e.g. for a tag field `x` in key `k`, if we insert json `a = {"x": "hello;hi"}`, then the low-level ops are:
   ```
   write:  k | TAG_FIELD | x | hello | a -> (nil)
   write:  k | TAG_FIELD | x | hi | a -> (nil)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#issuecomment-1916895313

   So only "tag" is support currently?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#issuecomment-1914946382

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2066) **Quality Gate passed**  
   The SonarCloud Quality Gate passed, but some issues were introduced.
   
   [3 New issues](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=2066&resolved=false&inNewCodePeriod=true)  
   [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=2066&resolved=false&inNewCodePeriod=true)  
   [60.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2066&metric=new_coverage&view=list)  
   [1.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2066&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2066)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#discussion_r1468823325


##########
src/types/redis_search_encoding.h:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#pragma once
+
+#include <encoding.h>
+#include <storage/redis_metadata.h>
+
+namespace redis {
+
+inline constexpr auto kErrorInsufficientLength = "insufficient length while decoding metadata";
+
+enum class SearchSubkeyType : uint8_t {

Review Comment:
   What do `TAG_FIELD_META` and `TAG_FIELD` means?



##########
src/types/redis_search_encoding.h:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#pragma once
+
+#include <encoding.h>
+#include <storage/redis_metadata.h>
+
+namespace redis {
+
+inline constexpr auto kErrorInsufficientLength = "insufficient length while decoding metadata";
+
+enum class SearchSubkeyType : uint8_t {
+  // search global metadata
+  PREFIXES = 1,
+
+  // field metadata for different types
+  TAG_FIELD_META = 64 + 1,
+
+  // field indexing for different types
+  TAG_FIELD = 128 + 1,
+};
+
+inline std::string ConstructSearchPrefixesSubkey() { return {(char)SearchSubkeyType::PREFIXES}; }
+
+struct SearchPrefixesMetadata {
+  std::vector<std::string> prefixes;
+
+  void Encode(std::string *dst) const {
+    for (const auto &prefix : prefixes) {
+      PutFixed32(dst, prefix.size());
+      dst->append(prefix);
+    }
+  }
+
+  rocksdb::Status Decode(Slice *input) {
+    uint32_t size = 0;
+
+    while (GetFixed32(input, &size)) {
+      if (input->size() < size) return rocksdb::Status::Corruption(kErrorInsufficientLength);
+      prefixes.emplace_back(input->data(), size);
+      input->remove_prefix(size);
+    }
+

Review Comment:
   Should we check `input->size() == 0` here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#discussion_r1468824859


##########
src/types/redis_search_encoding.h:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#pragma once
+
+#include <encoding.h>
+#include <storage/redis_metadata.h>
+
+namespace redis {
+
+inline constexpr auto kErrorInsufficientLength = "insufficient length while decoding metadata";
+
+enum class SearchSubkeyType : uint8_t {
+  // search global metadata
+  PREFIXES = 1,
+
+  // field metadata for different types
+  TAG_FIELD_META = 64 + 1,
+
+  // field indexing for different types
+  TAG_FIELD = 128 + 1,
+};
+
+inline std::string ConstructSearchPrefixesSubkey() { return {(char)SearchSubkeyType::PREFIXES}; }
+
+struct SearchPrefixesMetadata {
+  std::vector<std::string> prefixes;
+
+  void Encode(std::string *dst) const {
+    for (const auto &prefix : prefixes) {
+      PutFixed32(dst, prefix.size());
+      dst->append(prefix);
+    }
+  }
+
+  rocksdb::Status Decode(Slice *input) {
+    uint32_t size = 0;
+
+    while (GetFixed32(input, &size)) {
+      if (input->size() < size) return rocksdb::Status::Corruption(kErrorInsufficientLength);
+      prefixes.emplace_back(input->data(), size);
+      input->remove_prefix(size);
+    }
+

Review Comment:
   I think it can be guarenteed by users.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk commented on PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#issuecomment-1914668942

   > > > Like RediSearch, we will track all HASH and JSON commands and adjust our indexes accordingly.
   > > 
   > > 
   > > I mean, when start the process, we should "LIST" all indexes
   > 
   > Ahh I got your point.
   > 
   > I think we can add a common prefix for all index key, or put them to a new CF. Currently I prefer the latter.
   
   This skeleton code looks good to me. I also prefer the latter one if we want to keep the common prefix since the current column families are not for this purpose. But we need to do a little backward compatibility work while adding a new column family.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#issuecomment-1913585411

   How can we list all indexes efficiently? 🤔


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#discussion_r1468848714


##########
src/types/redis_search_encoding.h:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#pragma once
+
+#include <encoding.h>
+#include <storage/redis_metadata.h>
+
+namespace redis {
+
+inline constexpr auto kErrorInsufficientLength = "insufficient length while decoding metadata";
+
+enum class SearchSubkeyType : uint8_t {

Review Comment:
   🤔So this is different type of subkey?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice merged PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#discussion_r1468826283


##########
src/types/redis_search_encoding.h:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#pragma once
+
+#include <encoding.h>
+#include <storage/redis_metadata.h>
+
+namespace redis {
+
+inline constexpr auto kErrorInsufficientLength = "insufficient length while decoding metadata";
+
+enum class SearchSubkeyType : uint8_t {

Review Comment:
   `TAG_FIELD_META` means metadata of this index (field, typed `tag`), and `TAG_FIELD` simply stores the index.
   
   e.g. for a tag field `x` in key `k`, if we insert json `a = {"x": "hello;hi"}`, then the low-level ops are:
   ```
   write:  k | TAG_FIELD | x | hello | a -> (nil)
   write:  k | TAG_FIELD | x | hi | a -> (nil)
   ```
   
   And the metadata of `x` may be:
   ```
   k | TAG_FIELD_META | x -> ; | false
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#issuecomment-1914241469

   > > Like RediSearch, we will track all HASH and JSON commands and adjust our indexes accordingly.
   > 
   > I mean, when start the process, we should "LIST" all indexes
   
   Ahh I got your point.
   
   I think we can add a common prefix for all index key, or put them to a new CF. Currently I prefer the latter.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#issuecomment-1913554132

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2066) **Quality Gate passed**  
   The SonarCloud Quality Gate passed, but some issues were introduced.
   
   [3 New issues](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=2066&resolved=false&inNewCodePeriod=true)  
   [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=2066&resolved=false&inNewCodePeriod=true)  
   [60.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2066&metric=new_coverage&view=list)  
   [1.1% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=2066&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=2066)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Initialize metadata and tag indexing encoding for RediSearch [kvrocks]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on PR #2066:
URL: https://github.com/apache/kvrocks/pull/2066#issuecomment-1913914779

   > Like RediSearch, we will track all HASH and JSON commands and adjust our indexes accordingly.
   
   I mean, when start the process, we should "LIST" all indexes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org