For version 6.0.8, In raxGenericInsert() funtion,OOM hander exist one queston. When we insert one key string,walk to one termial node( h ),that is h->size is zero,but follow is happened: raxNode *newh = raxCompressNode(h,s+i,comprsize,&child); if (newh == NULL) goto oom;
error handler is follow: if (h->size == 0) { h->isnull = 1; h->iskey = 1; rax->numele++; / Compensate the next remove. / assert(raxRemove(rax,s,i,NULL) != 0); } errno = ENOMEM; return 0;
We release the current existing key-value,but it is not new one。
Comment From: sundb
@damagao In fact, all the oom code in rax will be dead code, because oom will be handled by zmalloc_default_oom() in redis, and the oom code will be there because rax is moved from https://github.com/antirez/rax, where oom needs to be handled manually.
On the other hand, this code seems to be fine, when oom, if the terminal node length is 0, we will remove it.
Comment From: damagao
@sundb When we insert one key string,walk to one termial node( h ),that is h->size is zero,but follow is happened: raxNode *newh = raxCompressNode(h,s+i,comprsize,&child); if (newh == NULL) goto oom;
when oom, if the terminal node length is 0, we will remove it which is existing(old) node , not inserted (new) node.
Comment From: sundb
@damagao Not sure I understand what you mean, can you give a test code?
Comment From: sundb
@damagao It looks like you are right, when creating a compressed node fails, it does trigger the assert(raxRemove(rax,s,i,NULL) ! = 0); assertion.
I'm not sure it's worth fixing it, maybe we should remove this oom handling.