func insert(session *gocql.Session) { for value := range ops_insert { query := session.Query(`INSERT INTO stress_table (key1,key2,key3,col1,col2,col3) VALUES (?,?,?,?,?,?)`, value[0], value[1], value[2], value[3], value[4], value[5]) if err := query.Exec(); err != nil { log.Fatal(err) } } done <- true }
func (writer *queueWriter) writeBatch(db *gocql.Session, requests []*batchRequest) { dbBatch := gocql.NewBatch(gocql.UnloggedBatch) i := int64(0) for _, request := range requests { for _, item := range request.items { itemID := writer.nextIndex + i dbBatch.Query(`INSERT INTO queue_items (queue_id, item_id, item_value) VALUES (?, ?, ?)`, writer.id, itemID, item) i++ } } err := db.ExecuteBatch(dbBatch) writer.respond(requests, err) }
func createks(session *gocql.Session, ks string, table string) { if err := session.Query(fmt.Sprintf( `CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1 };`, ks)).Exec(); err != nil { log.Fatalf("Could not create keyspace %s : %s", ks, err) } else { log.Printf("Success::Keyspace %s was created or already exists", ks) } session.Query(fmt.Sprintf("use %s;", ks)).Exec() if err := session.Query(fmt.Sprintf( `CREATE TABLE IF NOT EXISTS %s ( key1 int, key2 int, key3 int, col1 int, col2 int, col3 int, PRIMARY KEY (key1,key2,key3));`, table)).Exec(); err != nil { log.Fatalf("Could not create table %s : %s", table, err) } else { log.Printf("Success::Table %s was created or already exists", table) } }