buraksezer / olric

Distributed, in-memory key/value store and cache. It can be used as an embedded Go library and a language-independent service.
Apache License 2.0
3.14k stars 117 forks source link

Keys starting with "e" can't be used #23

Closed pojntfx closed 4 years ago

pojntfx commented 4 years ago

First of all: Thanks for this amazing KV store! It is tremendously helpful in building the distributed routing logic for gloeth.

Right now though, it does not seem to be possible to use a key starting with "e":

[127.0.0.1:3320] » use testing
use testing
[127.0.0.1:3320] » put a b
[127.0.0.1:3320] » get a
b
[127.0.0.1:3320] » put b a
[127.0.0.1:3320] » get b
a
[127.0.0.1:3320] » put e a
[127.0.0.1:3320] » get e
Failed to call get e on testing: key not found
[127.0.0.1:3320] » put e1234 a
[127.0.0.1:3320] » get e1234
Failed to call get e1234 on testing: key not found
[127.0.0.1:3320] » put "efss" a
[127.0.0.1:3320] » get "efss"
Failed to call get "efss" on testing: key not found
[127.0.0.1:3320] » get efss
Failed to call get efss on testing: key not found
[127.0.0.1:3320] » put esadfjaslfjalsfjlsdjflsjdfajksdjfla a
[127.0.0.1:3320] » get esadfjaslfjalsfjlsdjflsjdfajksdjfla
Failed to call get esadfjaslfjalsfjlsdjflsjdfajksdjfla on testing: key not found
[127.0.0.1:3320] » 
2020/03/26 20:56:08 [INFO] Routing table has been pushed by 0.0.0.0:3320 => routing.go:488
2020/03/26 20:56:08 [INFO] Stale DMap (backup: false) has been deleted: testing on PartID: 9 => dmap_delete.go:34
2020/03/26 20:56:08 [INFO] Stale DMap (backup: false) has been deleted: testing on PartID: 15 => dmap_delete.go:34
2020/03/26 20:56:08 [INFO] Stale DMap (backup: false) has been deleted: testing on PartID: 30 => dmap_delete.go:34

Thanks for any help!

pojntfx commented 4 years ago

System information:

pojntfx@Felixs-MBP ~ % neofetch 
                    'c.          pojntfx@Felixs-MBP.fritz.box 
                 ,xNMM.          ---------------------------- 
               .OMMMMo           OS: macOS 10.15.3 19D76 x86_64 
               OMMM0,            Host: MacBookPro13,2 
     .;loddo:' loolloddol;.      Kernel: 19.3.0 
   cKMMMMMMMMMMNWMMMMMMMMMM0:    Uptime: 2 days, 22 hours, 14 mins 
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Packages: 205 (port), 137 (brew) 
 XMMMMMMMMMMMMMMMMMMMMMMMX.      Shell: zsh 5.7.1 
;MMMMMMMMMMMMMMMMMMMMMMMM:       Resolution: 1920x1080@2x, 1440x900@2x 
:MMMMMMMMMMMMMMMMMMMMMMMM:       DE: Aqua 
.MMMMMMMMMMMMMMMMMMMMMMMMX.      WM: Quartz Compositor 
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.    WM Theme: Blue (Dark) 
 .XMMMMMMMMMMMMMMMMMMMMMMMMMMk   Terminal: Apple_Terminal 
  .XMMMMMMMMMMMMMMMMMMMMMMMMK.   Terminal Font: SFMono-Regular 
    kMMMMMMMMMMMMMMMMMMMMMMd     CPU: Intel i7-6567U (4) @ 3.30GHz 
     ;KMMMMMMMWXXWMMMMMMMk.      GPU: Intel Iris Graphics 550 
       .cooc,.    .,coo:.        Memory: 10604MiB / 16384MiB
buraksezer commented 4 years ago

Hi,

First of all: Thanks for this amazing KV store! It is tremendously helpful in building the distributed routing logic for gloeth.

I'm glad to hear that. I hope that Olric would be useful tool for you. Please share your experiences you have.

After a short investigation, I managed to identify the bug. It's caused by strings.TrimLeft function. Take a look at this:

package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println("strings.TrimLeft for 'get e':", strings.TrimLeft("get e", "get "))
    fmt.Println("strings.TrimLeft for 'get b':", strings.TrimLeft("get b", "get "))
}

This small snippet prints the following:

strings.TrimLeft for 'get e':
strings.TrimLeft for 'get b': b

Obviously this is a stupid bug in Golang's stdlib. I'll investigate this. When I replaced strings.TrimLeft with strings.TrimPrefix, the problem is gone.

olric-cli in master should work as expected. Could you please try it?

Note on deploying Olric in embedded-member scenario: memberlist configuration can be painful. I would like to assist you during integration process. You should feel free to open an issue with question tag, if you have questions about integration. There are two important issues on the issue tracker which includes too many information about the integration. Please take a look at:

pojntfx commented 4 years ago

@buraksezer Thanks for the speedy reply! Can confirm; the issue is no longer present. I'll be sure to take a look at the other memberlist config-related issues.

isavcic commented 4 years ago

@buraksezer you misunderstood how TrimLeft works.

package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println("strings.TrimLeft for 'get g':", strings.TrimLeft("get g", "get "))
    fmt.Println("strings.TrimLeft for 'get e':", strings.TrimLeft("get e", "get "))
    fmt.Println("strings.TrimLeft for 'get t':", strings.TrimLeft("get t", "get "))
    fmt.Println("strings.TrimLeft for 'get b':", strings.TrimLeft("get b", "get "))
}

returns

strings.TrimLeft for 'get g': 
strings.TrimLeft for 'get e': 
strings.TrimLeft for 'get t': 
strings.TrimLeft for 'get b': b

The documentation clearly states:

To remove a prefix, use TrimPrefix instead.

buraksezer commented 4 years ago

@isavcic Thank you very much for clarification. I realized my fault short after. I had reimplemented olric-cli tool a few weeks ago. I used strings.Fields to parse the commands.