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

Golang indexed column issues #1149

Open
barum opened this issue Apr 5, 2019 · 6 comments
Open

Golang indexed column issues #1149

barum opened this issue Apr 5, 2019 · 6 comments
Assignees
Labels
community/request Issues created by external users kind/bug This issue is a bug

Comments

@barum
Copy link

barum commented Apr 5, 2019

here is my go program

package main

import (
	"fmt"
	"log"
	"time"

	"github.com/gocql/gocql"
)

func main() {
	// Connect to the cluster.
	cluster := gocql.NewCluster("127.0.0.1", "127.0.0.2", "127.0.0.3")

	// Use the same timeout as the Java driver.
	cluster.Timeout = 12 * time.Second

	// Create the session.
	session, _ := cluster.CreateSession()
	defer session.Close()

	// Set up the keyspace and table.
	if err := session.Query("CREATE KEYSPACE IF NOT EXISTS ybdemo").Exec(); err != nil {
		log.Fatal(err)
	}
	fmt.Println("Created keyspace ybdemo")

	if err := session.Query(`DROP TABLE IF EXISTS ybdemo.employee`).Exec(); err != nil {
		log.Fatal(err)
	}
	var createStmt = `CREATE TABLE ybdemo.employee (id int, name varchar, 
                                                           age int, 
														   language varchar,
														   PRIMARY KEY(id))  WITH transactions = { 'enabled' : true }`
	if err := session.Query(createStmt).Exec(); err != nil {
		log.Fatal(err)
	}
	fmt.Println("Created table ybdemo.employee")

	createStmt = `CREATE index if not exists employee_age_idx on ybdemo.employee (age) include (name)`
	if err := session.Query(createStmt).Exec(); err != nil {
		log.Fatal(err)
	}
	fmt.Println("Created index")

	// Insert into the table.
	for i := 0; i < 100; i++ {

		insertStmt := fmt.Sprintf("INSERT INTO ybdemo.employee(id, name, age, language)  VALUES (%d, 'John+%d', %d, 'Go')", i+1, i+1, ((i+500)%20)+1)
		if err := session.Query(insertStmt).Exec(); err != nil {
			log.Fatal(err)
		}
		fmt.Printf("Inserted data: %s\n", insertStmt)
	}
	// var insertStmt string = "INSERT INTO ybdemo.employee(id, name, age, language)" +
	// 	" VALUES (1, 'John', 35, 'Go')"
	// if err := session.Query(insertStmt).Exec(); err != nil {
	// 	log.Fatal(err)
	// }
	// fmt.Printf("Inserted data: %s\n", insertStmt)

	// Read from the table.
	var name string
	var age int
	var language string
	iter := session.Query(`SELECT name, age, language FROM ybdemo.employee WHERE id = 1`).Iter()
	fmt.Printf("Query for id=1 returned: ")
	for iter.Scan(&name, &age, &language) {
		fmt.Printf("Row[%s, %d, %s]\n", name, age, language)
	}

	if err := iter.Close(); err != nil {
		log.Fatal(err)
	}
}

First time, completes. second time it dies.
Also after first time complete, I try CQLSH and can not query on indexed column. get a timeout.

select * from ybdemo.employee where age = 1;
OperationTimedOut: errors={'127.0.0.1': 'Client request timeout. See Session.execute[_async](timeout)'}, last_host=127.0.0.1
cqlsh> select * from ybdemo.employee where id = 1;

 id | name   | age | language
----+--------+-----+----------
  1 | John+1 |   0 |       Go
@barum
Copy link
Author

barum commented Apr 5, 2019

 cqlsh> desc keyspace ybdemo;

CREATE KEYSPACE ybdemo WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}  AND durable_writes = true;

CREATE TABLE ybdemo.employee (
    id int PRIMARY KEY,
    name text,
    age int,
    language text
) WITH default_time_to_live = 0;
CREATE INDEX employee_age_idx ON ybdemo.employee (age, id);

@kmuthukk
Copy link
Collaborator

kmuthukk commented Apr 5, 2019

hi @barum

Looks like you are testing a three node:
gocql.NewCluster("127.0.0.1", "127.0.0.2", "127.0.0.3")

Can you share the steps on how the cluster was created (e.g., yb-ctl with rf 3?) etc.? And do you see any relevant logs (like a yb-tserver.FATAL/yb-master.FATAL file in the data directory)?

@rkarthik007 rkarthik007 added the kind/bug This issue is a bug label Apr 5, 2019
@kmuthukk
Copy link
Collaborator

kmuthukk commented Apr 5, 2019

hi @barum

I tried this a few times on a "3-node local" cluster on CentOS, and it worked fine for me:

% ./bin/yb-ctl --replication_factor 3 start

% ~/yugabyte-1.2.3.0/bin/yb-ctl status
2019-04-05 15:44:13,574 INFO: Server is running: type=master, node_id=1, PID=28001, admin service=http://127.0.0.1:7000
2019-04-05 15:44:13,585 INFO: Server is running: type=master, node_id=2, PID=28004, admin service=http://127.0.0.2:7000
2019-04-05 15:44:13,597 INFO: Server is running: type=master, node_id=3, PID=28007, admin service=http://127.0.0.3:7000
2019-04-05 15:44:13,609 INFO: Server is running: type=tserver, node_id=1, PID=28010, admin service=http://127.0.0.1:9000, cql service=127.0.0.1:9042, redis service=127.0.0.1:6379, pgsql service=127.0.0.1:5433
2019-04-05 15:44:13,621 INFO: Server is running: type=tserver, node_id=2, PID=28016, admin service=http://127.0.0.2:9000, cql service=127.0.0.2:9042, redis service=127.0.0.2:6379, pgsql service=127.0.0.2:5433
2019-04-05 15:44:13,632 INFO: Server is running: type=tserver, node_id=3, PID=28025, admin service=http://127.0.0.3:9000, cql service=127.0.0.3:9042, redis service=127.0.0.3:6379, pgsql service=127.0.0.3:5433

And ran this multiple times:

$ go run cql.go
...
...
Inserted data: INSERT INTO ybdemo.employee(id, name, age, language)  VALUES (99, 'John+99', 19, 'Go')
Inserted data: INSERT INTO ybdemo.employee(id, name, age, language)  VALUES (100, 'John+100', 20, 'Go')
Query for id=1 returned: Row[John+1, 1, Go]

Is it possible that there aren't sufficient resources on your node to run a multi-process (RF=3) local cluster?

Do you want to try with --replication_factor 1 instead for local testing?

@barum
Copy link
Author

barum commented Apr 5, 2019

If I try 1 or 3 instances the issue is the same.
I am on docker version of YB.
Even when I try to use your examples in CQLSH, i still have same issues.
Would be glad to setup a sharing session to show you.

@barum
Copy link
Author

barum commented Apr 5, 2019

nope. same issues on local and docker.

@mbautin mbautin self-assigned this Apr 7, 2019
@yugabyte-ci yugabyte-ci added the community/request Issues created by external users label Jul 17, 2019
@ttyusupov
Copy link
Contributor

Hi @barum , can you try again with the latest release? https://docs.yugabyte.com/latest/quick-start/install/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community/request Issues created by external users kind/bug This issue is a bug
Projects
None yet
Development

No branches or pull requests

6 participants