Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix log error of radix tree deserialization. #1811

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions modules/llm-cache/radix-tree/radix-tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@ limitations under the License.

namespace vineyard {

RadixTree::RadixTree(int cacheCapacity) {
RadixTree::RadixTree(int cacheCapacity, bool withRoot) {
this->tree = raxNew();
// add one to the cache capacity because we insert a root node to the tree.
this->cacheCapacity = cacheCapacity + 1;
this->nodeCount = 0;

// prepare root node
std::vector<int> rootToken = {INT32_MAX};
std::shared_ptr<NodeData> evictedNode;
this->InsertInternal(rootToken, evictedNode);
if (VLOG_IS_ON(100)) {
VLOG(100) << raxShow(this->tree);
if (withRoot) {
std::vector<int> rootToken = {INT32_MAX};
std::shared_ptr<NodeData> evictedNode;
this->InsertInternal(rootToken, evictedNode);
if (VLOG_IS_ON(100)) {
VLOG(100) << raxShow(this->tree);
}
raxNode* dataNode =
raxFindAndReturnDataNode(this->tree, rootToken, NULL, false);
DataWrapper* data = new DataWrapper();
data->data = nullptr;
data->dataLength = 0;
dataNode->custom_data = data;
VLOG(100) << "root data wrapper:" << data;
dataNode->issubtree = true;
this->rootToken = rootToken;
}
raxNode* dataNode =
raxFindAndReturnDataNode(this->tree, rootToken, NULL, false);
DataWrapper* data = new DataWrapper();
data->data = nullptr;
data->dataLength = 0;
dataNode->custom_data = data;
VLOG(100) << "root data wrapper:" << data;
dataNode->issubtree = true;
this->rootToken = rootToken;
}

RadixTree::~RadixTree() {
Expand Down Expand Up @@ -430,7 +432,7 @@ std::shared_ptr<RadixTree> RadixTree::Deserialize(std::string data) {
// is created by upper layer. Here just recover it from serialized
// string.
std::shared_ptr<RadixTree> radixTree =
std::make_shared<RadixTree>(cacheCapacity);
std::make_shared<RadixTree>(cacheCapacity, false);
radixTree->nodeCount = tokenList.size();

if (VLOG_IS_ON(100)) {
Expand All @@ -450,8 +452,8 @@ std::shared_ptr<RadixTree> RadixTree::Deserialize(std::string data) {
int retval =
raxInsertAndReturnDataNode(radixTree->tree, tokenList[i], data,
reinterpret_cast<void**>(&dataNode), NULL);
if (retval == 0 || dataNode == NULL) {
LOG(ERROR) << "Insert token list failed";
if (retval == 0) {
LOG(WARNING) << "Overwrite the data of the node";
}
dataNode->timestamp = timestampList[i];
dataNode->numnodes = subTreeSizeList[i];
Expand Down
2 changes: 1 addition & 1 deletion modules/llm-cache/radix-tree/radix-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class RadixTree : public std::enable_shared_from_this<RadixTree> {
const std::vector<int>& tokens, std::shared_ptr<NodeData>& header);

public:
explicit RadixTree(int cacheCapacity);
explicit RadixTree(int cacheCapacity, bool withRoot = true);

~RadixTree();

Expand Down
Loading