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

View is empty, if log forced the keys/values come back #197

Closed
edgar86cru opened this issue Jun 26, 2019 · 6 comments
Closed

View is empty, if log forced the keys/values come back #197

edgar86cru opened this issue Jun 26, 2019 · 6 comments

Comments

@edgar86cru
Copy link

Hi everybody.
I had an error trying to get some values from a View.
This is the original code:

var found interface{}
if found, err = domain.gokaBase.view.Get(string(id)); err != nil {
	domain.logger.WithError(err).Error("error while searching device")
	return Device{}, err
} else if found == nil {
	domain.logger.Error("did not find device of given id")
	return Device{}, errors.New("not found")
}

The err and the found were always nil for all ids but I check in another project and I have some key/value stored in the View.
When I forced the log of found and err adding the code below, I get back the values of my View:

var found interface{}
found, err = domain.gokaBase.view.Get(string(id))
fmt.Printf("found: %v\n", found)
fmt.Printf("err: %v\n", err)

Someone have already this malfunction??
Thank you

@db7
Copy link
Collaborator

db7 commented Jun 26, 2019

Once you start the view, you have to wait until it catches up with Kafka. If you query the view before fully recovering it, it won't know about the value for your key.

I am not sure whether that is your case, but if it is, you can solve it by waiting the view to recover:

for !view.Recovered() {
    time.Sleep(time.Second)
}

...
var found interface{}
if found, err = domain.gokaBase.view.Get(string(id)); err != nil {
	domain.logger.WithError(err).Error("error while searching device")
	return Device{}, err
} else if found == nil {
	domain.logger.Error("did not find device of given id")
	return Device{}, errors.New("not found")
}

The table is locally stored in /tmp/goka/.... You can delete that folder to force your view to recover again.

Let me know if that helped.

@edgar86cru
Copy link
Author

Thank you for your reply. I will try the code that you wrote.
I didn't know about the view.Recovered() but I'm not sure if it's really this the problem because even when I asked the value/key after a while (minutes, hours) the view was always empty.

@db7
Copy link
Collaborator

db7 commented Jun 28, 2019

Ah, ok. Another idea: Have you created the table with a Java Client?

The golang client (Sarama) uses another hashing and the views won’t find your keys.

To use the same hasher as Java you have to pass it when you create the view or processor. Check issue #186.

@edgar86cru
Copy link
Author

To create the view I used a golang client.
Thank you for your quick reply

@db7
Copy link
Collaborator

db7 commented Aug 7, 2019

@edgar86cru are you still facing problems or can I close this issue?

@edgar86cru
Copy link
Author

@db7 sorry I forgot to reply... You can close the issue it works with the code that you passed me, the first time that I tried I forgot to Run the view. Thank you again

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

No branches or pull requests

2 participants