go


Make a blocking/consistent/predictable reply/request on ScyllaDB via GoCQL


Sometimes when running a command it shows a timeout (gocql: no response received from cassandra within timeout period), for example:
package main
import "fmt"
import "github.com/gocql/gocql"
import "time"
import "log"
func main() {
clust := gocql.NewCluster(`172.17.0.2`) // docker#localhost
clust.Keyspace = `test4`
clust.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: 3}
db, err := clust.CreateSession()
defer db.Close()
if err != nil {
log.Fatal(err)
return
}
fmt.Println(`test4: scylladb`)
if err := db.Query(`DROP TABLE test4`).Exec(); err != nil {
log.Println(err)
}
if err := db.Query(`CREATE TABLE test4 (bucket text, k text, v TEXT, PRIMARY KEY(bucket,k))`).Exec(); err != nil {
log.Fatal(err)
return
}
const max = 999
const jump = 40
t := time.Now()
for x := 1; x <= max; x++ {
err = db.Query(fmt.Sprintf(`INSERT INTO test4(bucket,k,v)VALUES('foo','%05d','%05d')`, x, x)).Exec()
if err != nil {
log.Fatal(err)
return
}
if x % 200 == 0 {
fmt.Print(`.`)
}
}
dur := time.Now().Sub(t)
fmt.Printf("INSERT: %v (%.2f ms/op)\n", dur, float64(dur.Nanoseconds()) / 1000000 / max)
t = time.Now()
for x := 1; x <= max; x++ {
err = db.Query(fmt.Sprintf(`UPDATE test4 SET v = '%06d' WHERE bucket = 'foo' AND k = '%05d'`, x, x)).Exec()
if err != nil {
log.Fatal(err)
return
}
if x % 200 == 0 {
fmt.Print(`.`)
}
}
dur = time.Now().Sub(t)
fmt.Printf("UPDATE: %v (%.2f ms/op)\n", dur, float64(dur.Nanoseconds()) / 1000000 / max)
t = time.Now()
ops := int64(0)
for y := 2; y < jump; y++ {
for x := max - 1; x > 0; x -= y {
ops++
iter := db.Query(fmt.Sprintf(`SELECT k, v FROM test4 WHERE bucket = 'foo' AND k >= '%05d' ORDER BY k ASC LIMIT %d`, x, y * y)).Iter()
for {
m := map[string]interface{}{}
if !iter.MapScan(m) {
break
}
}
iter.Close()
if ops % 500 == 0 {
fmt.Print(`.`)
}
}
for x := 1; x < max; x += y {
ops++
iter := db.Query(fmt.Sprintf(`SELECT k, v FROM test4 WHERE bucket = 'foo' AND k <= '%05d' ORDER BY k DESC LIMIT %d`, x, y * y)).Iter()
for {
m := map[string]interface{}{}
if !iter.MapScan(m) {
break
}
}
iter.Close()
if ops % 500 == 0 {
fmt.Print(`.`)
}
}
}
dur = time.Now().Sub(t)
fmt.Printf("SELECT: %v (%.2f ms/op)\n", dur, float64(dur.Nanoseconds()) / 1000000 / float64(ops))
}
It shows inconsistent output:
$ go run scylla.go
test4: scylladb
2017/05/16 12:09:05 gocql: no response received from cassandra within timeout period
2017/05/16 12:09:05 gocql: no response received from cassandra within timeout period
exit status 1
$ go run scylla.go
test4: scylladb
....INSERT: 188.277521ms (0.19 ms/op)
....UPDATE: 150.403282ms (0.15 ms/op)
.............SELECT: 5.357779756s (0.82 ms/op)
$ go run scylla.go
test4: scylladb
2017/05/16 12:09:50 gocql: no response received from cassandra within timeout period
....INSERT: 142.91132ms (0.14 ms/op)
....UPDATE: 144.272872ms (0.14 ms/op)
.............SELECT: 5.268130283s (0.81 ms/op)
$ go run scylla.go
test4: scylladb
2017/05/16 12:10:00 gocql: no response received from cassandra within timeout period
2017/05/16 12:10:00 gocql: no response received from cassandra within timeout period
exit status 1
$ go run scylla.go
test4: scylladb
....INSERT: 184.402052ms (0.18 ms/op)
....UPDATE: 158.200184ms (0.16 ms/op)
.............SELECT: 5.345212835s (0.82 ms/op)
How to make it consistent? I need to be sure if a command completed successfully.. Or should I loop the DROP TABLE/CREATE TABLE command manually?

Related Links

GOPATH variable not persisting
Is main.go required in a Go project?
How to “cast” a pointer back to a value in Golang?
Does the goroutines created in the same goroutines execute always in order?
using libraries in Golang
How do I pass a sort interface implementation type as a function parameter?
mgo convert bson.objectId to string(hex) in html template
Can I add a field to an existing struct with Go?
Is there any way to export a Go callback with const parameters?
How to unmarshal YAML in Go
How can I get the nearest city to geo-coordinates with Go?
Golang Map of http.ResponseWriters
How to store unicode in a Go struct (golang)
boolean values set to true unintentionally changing to false
Referencing struct field from another package
Where to initialise git in Go project

Categories

HOME
phantom-dsl
c++11
devise
error-handling
vscode-extensions
ms-access-2016
opendj
soa
pyqt4
regular-language
python-multithreading
data-visualization
joomla3.0
qpython
php-5.6
openbugs
code-generation
gource
gruntfile
intershop
imessage
gmm
enterprise-miner
symbols
kendo-mobile
blade
inno-download-plugin
highstock
interpreter
froala
android-sharedpreferences
jasmine-node
spotipy
boost-asio
spring-security4
simplecv
hreflang
android-gridview
openerp-7
apic
sql-server-ce
openalpr
metawidget
jvmti
p4merge
branching-and-merging
postgresql-8.4
servermanager
double-click
xbmc
gitlist
tf
openblas
reindex
video-conferencing
oracleclient
git-flow
reshape
seq
java-websocket
jtree
filenet
choice
slackware
reporting-services-2012
dimension
xdoclet
firebase-security
nss
aurora
uiactionsheet
pushbots
httpruntime.cache
java-money
oracle-spatial
canalyzer
dnssec
nsurlsessiondatatask
zxspectrum
cakephp-2.7
java-security
grouping-sets
variadic-templates
nodelist
packet-sniffers
android-cookiemanager
cbind
encryption-asymmetric
mintty
getopt
syndicationfeed
spring-3
scriptaculous
hidapi
unit-of-work
rolify
neos-server
asdf
facebook-timeline
traceability
stacky
apache-abdera
saleslogix
mapping-by-code
tournament
xui
unattended-processing
cdonts
socketserver
undefined-index
office-2007
application-verifier
purepdf
web-application-project
dsl-tools
cldc
software-lifecycle
flvplayback
unmanagedresources
wspbuilder

Resources

Encrypt Message