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

ScanAllObjects doesn't return generation #260

Closed
doctornick42 opened this issue Apr 24, 2019 · 3 comments
Closed

ScanAllObjects doesn't return generation #260

doctornick42 opened this issue Apr 24, 2019 · 3 comments

Comments

@doctornick42
Copy link

Hello!

I created a structure containing a field marked with asm:"gen" tag. Should the ScanAllObjects method fill that field?

Here's example of my code:

package main

import (
	aerospike "github.com/aerospike/aerospike-client-go"
	"fmt"
)

const (
	namespace = "testns"
	set = "testset"
)

// This is only for this example.
// Please handle errors properly.
func panicOnError(err error) {
	if err != nil {
		panic(err)
	}
}

type TestStruct struct {
	Key int64 `as:"key"`
	A string `as:"a"`
	B int64	`as:"b"`
	Gen uint32 `asm:"gen"`
}

func main() {
	fmt.Println("Connecting to Aerospike")

	// define a client to connect to
	client, err := aerospike.NewClient("127.0.0.1", 3000)
	panicOnError(err)
  
	fmt.Println("Connected successfully")

	scanedObjs := make(chan *TestStruct, 1)

	rs, err := client.ScanAllObjects(nil, scanedObjs, namespace, set)
	panicOnError(err)

	ts := &TestStruct{
		Key: 123,
		A: "test",
		B: 456,
	}

	key, err := aerospike.NewKey(namespace, set, ts.Key)
	panicOnError(err)

	err = client.PutObject(nil, key, ts)
	panicOnError(err)

	for so := range scanedObjs {
		fmt.Printf("[FROM ScanAllObjects] Key: %v, generation: %v\r\n", so.Key, so.Gen)
		
		rec, err := client.GetHeader(nil, key)
		panicOnError(err)
		fmt.Printf("[FROM GetHeader] Key: %v, generation: %v\r\n", so.Key, rec.Generation)
	}

	for e := range rs.Errors {
		panicOnError(e)
	}

	return
  }

On the first run the output is:

Connecting to Aerospike
Connected successfully
[FROM ScanAllObjects] Key: 123, generation: 0
[FROM GetHeader] Key: 123, generation: 1

On the second one it's:

Connecting to Aerospike
Connected successfully
[FROM ScanAllObjects] Key: 123, generation: 0
[FROM GetHeader] Key: 123, generation: 2

So, is it possible to receive generation during scan? Maybe I should use some ScanPolicy for it or there's no way to force the method to get generation?

Thanks in advance!

@khaf
Copy link
Collaborator

khaf commented Apr 24, 2019

Thanks for your report. This looks like a bug. Will release the fix before the weekend.

@khaf khaf closed this as completed in f257953 Apr 25, 2019
@khaf
Copy link
Collaborator

khaf commented Apr 25, 2019

The fix is released.

@doctornick42
Copy link
Author

@khaf
It works! Thank you for fixing it so fast.

gburanov pushed a commit to remerge/aerospike-client-go that referenced this issue Nov 15, 2019
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