mattes / migrate

Database migrations. CLI and Golang library.
Other
2.29k stars 326 forks source link

all cassandra migrate commands take 3+ minutes to execute #86

Open tednaleid opened 8 years ago

tednaleid commented 8 years ago

I could have something configured wrong, but every command that I run through migrate takes very slightly over 3 minutes to run. This example migration does a simple select on an empty table:

migrate -url cassandra://192.168.99.100/items -path ./migrations migrate +1
> 0001_foobar.up.cql

3.0054 minutes

This create statement is just making a new set of cql files in the migrations directory:

time migrate -url cassandra://192.168.99.100/items -path ./migrations create foobar3
Version 3 migration files created in ./migrations:
0003_foobar3.up.cql
0003_foobar3.down.cql
migrate -url cassandra://192.168.99.100/items -path ./migrations create   0.01s user 0.02s system 0% cpu 3:00.28 total

I'm running against a docker container using this docker-compose.yml file and the IP above is the docker-machine ip default value:

cassandra:
  image: library/cassandra:2.2.3
  ports:
    - "9160:9160"
    - "9042:9042"
  volumes:
    - ./migrations:/migrations

It feels like there's some sort of timeout going on within the migrate command or the gocql stuff. Interaction with the cassandra instance via cqlsh is speedy and normal, example running cqlsh directly inside the docker container:

time docker exec -it migratetest_cassandra_1 cqlsh -f migrations/0001_foobar.up.cql

 count
-------
     0

(1 rows)

Warnings :
Aggregation query used without partition key

docker exec -it migratetest_cassandra_1 cqlsh -f migrations/0001_foobar.up.cql  0.14s user 0.01s system 25% cpu 0.563 total

Has anyone seen weird 3 minute pauses with the cassandra migrate driver?

mojotalantikite commented 8 years ago

This isn't an issue with migrate, it's most likely due to the NATing from docker and the 3 minute pause is probably a 180 second timeout somewhere. Can you try by setting --net=host in your docker command, something like this:

docker run -d --net=host --name=cassandra -p 9042:9042 cassandra:2.2.3

Without the --net=host I'm getting the 3 minute pauses you experienced and with it I'm back to 2 seconds or so for completion.

shreyderina commented 8 years ago

I caught this problem too, but my cassandra not in docker. I wrote the following script using only gocql

package main

import (
    "fmt"
    "log"
    "github.com/gocql/gocql"
)

func main() {
    cluster := gocql.NewCluster("10.54.29.171")
    cluster.ProtoVersion = 4
    cluster.Authenticator = gocql.PasswordAuthenticator{Username: "cassandra", Password: "cassandra", }
    cluster.Keyspace = "myksp"
    cluster.Consistency = gocql.All
    session, err := cluster.CreateSession()

    if err != nil {
        fmt.Println(err)
    }
    defer session.Close()

    var version int

    if err := session.Query(`SELECT version FROM schema_migrations WHERE versionrow = ? limit 1`,
        1).Consistency(gocql.One).Scan(&version); err != nil {
        log.Fatal(err)
    }
    fmt.Println("Version:", version)
}

And my results are good. Correct version and very fast.

$ time go run main.go
Version: 1
real    0m2.456s

But then I used script with migrate

package main

import (
    "fmt"

    _ "github.com/mattes/migrate/driver/cassandra"
    "github.com/mattes/migrate/migrate"
)

func main() {
    version, err := migrate.Version("cassandra://cassandra:cassandra@10.54.29.171/myksp?protocol=4", "/home/migrations")
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
    fmt.Println(version)
}

I'm getting 3 minutes pause and incorrect version value:

$ time go run main.go
0
real    3m0.408s
nathany commented 7 years ago

This issue is resolved in the latest 1.4.1 version of the Gemnasium fork: https://github.com/gemnasium/migrate/pull/17

JulienTant commented 7 years ago

This is still true

nathany commented 7 years ago

Fyi, The gemnasium fork is in the process of being moved to https://github.com/db-journey.

mattes commented 7 years ago

What's the db journey and why is it a copy of this repo with no backlinks to migrate?

@nathany did you see the latest v3 efforts? https://github.com/mattes/migrate/tree/v3.0-prev

nathany commented 7 years ago

That's a question for @gravis. But I do see a back link in the README at https://github.com/db-journey/journey

Hadn't seen the v3 efforts, thanks for pointing that out.

mattes commented 7 years ago

Yeah, sorry, I was just looking at migrate repo. Reached out to him, see what he is up to.

mattes commented 7 years ago

That being said, v3 is looking really awesome. Sources are drivers, too now. Making it super simple to integrate with go-bindata for example. migrate v3 is a full rewrite. I have more news soon, once there is an actual release candidate.