facebookarchive / flashback

Capture and replay real mongodb workloads

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

panic: interface conversion: interface is int32, not float64

nikolaiderzhak opened this issue · comments

I am getting this error when starting replay with recorded OUTPUT json and go 1.4.2:

panic: interface conversion: interface is int32, not float64

goroutine 113 [running]:
github.com/ParsePlatform/flashback.(*OpsExecutor).execQuery(0xc20866b2c0, 0xc2085d0120, 0xc208697530, 0x0, 0x0)
        /home/ubuntu/gocode/src/github.com/ParsePlatform/flashback/ops_executor.go:50 +0x20e
github.com/ParsePlatform/flashback.*OpsExecutor.(github.com/ParsePlatform/flashback.execQuery)·fm(0xc2085d0120, 0xc208697530, 0x0, 0x0)
        /home/ubuntu/gocode/src/github.com/ParsePlatform/flashback/ops_executor.go:35 +0x4d
github.com/ParsePlatform/flashback.func·004(0x0, 0x0)
        /home/ubuntu/gocode/src/github.com/ParsePlatform/flashback/ops_executor.go:144 +0x2b5
github.com/ParsePlatform/flashback.retryOnSocketFailure(0xc208815e70, 0xc2086621a0, 0xc20803c420, 0x0, 0x0)
        /home/ubuntu/gocode/src/github.com/ParsePlatform/flashback/ops_executor.go:116 +0x47
github.com/ParsePlatform/flashback.(*OpsExecutor).Execute(0xc20866b2c0, 0xc208608050, 0x0, 0x0)
        /home/ubuntu/gocode/src/github.com/ParsePlatform/flashback/ops_executor.go:146 +0xc6
main.func·003(0xc20866b2c0, 0x68ab90, 0x7)
        /home/ubuntu/gocode/src/github.com/ParsePlatform/flashback/cmd/flashback/main.go:317 +0x6b
created by main.func·005
        /home/ubuntu/gocode/src/github.com/ParsePlatform/flashback/cmd/flashback/main.go:328 +0x725

$ go version
go version go1.4.2 linux/amd64

Fixed it with next patch:

diff --git a/ops_executor.go b/ops_executor.go
index 99d5160..71ee781 100644
--- a/ops_executor.go
+++ b/ops_executor.go
@@ -47,11 +47,11 @@ func (e *OpsExecutor) execQuery(
        query := coll.Find(content["query"])
        result := []Document{}
        if content["ntoreturn"] != nil {
-               ntoreturn := int(content["ntoreturn"].(float64))
+               ntoreturn := int(content["ntoreturn"].(int32))
                query.Limit(ntoreturn)
        }
        if content["ntoskip"] != nil {
-               ntoskip := int(content["ntoskip"].(float64))
+               ntoskip := int(content["ntoskip"].(int32))
                query.Skip(ntoskip)
        }
        err := query.All(&result)

Let me know if it is ok and I will create PR.

Please guard this with either a two-value type assertion or a type switch (and handle both cases).

Sorry I am not familiar with go lang. Could you show me proper fix ?

@tmc Thanks Travis. That is from stackoverflow I found too :).

Could you provide ready patch for our case ? I really have dull view of what need to be done with that tricky (for not familiar person) Go syntax.

I will use provided above patch meanwhile. Until I get some spare time to play with that improvement.

I just pushed a patch. Can you try the latest master and see if it fixes your issue? 97ad7ab

Travis was I writing my own on this, and you pushed right to master :P Anyhow both ways work, but I worry that we should not set query.Limit vs settings it to 0. It could change the test output if its normally returning 10k or 100k and we ask it for 0.

Thoughts?

@dbmurphy yeah you're right. How about bd3ffb0 ? We just return and log an error if ntoreturn or ntoskip are some type we don't recognize.

Yeah that looks good.

Sorry for delay. I have back to my benchmarking tasks and tested latest master (bd3ffb0) .

Did not get exceptions. So can I assume that the tool replays recorded operations correctly now ?

Yes, the unprotected type assertion is now fixed.