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

Golang inferred interfaces
Beego ORM MySql Connection Error
Why the following Golang code doesn't run?
How to make Go print enum fields as string?
Build errors in datastore while using golang/protobuf
How do I add external executable to Go project
Cannot build “chaintool/example02”
Golang how to fetch specific key (from multistructure) from the rest api json response
How we can know what kind of struct is on byte array
why the output order is changed when using `log.Println` and `fmt.Println`?
Running compiled code for linux on windows
golang time duration to string 2h instead 2h0m0s
Concurrent goroutines inside a for loop
go loadPage issue: invalid memory address or nil pointer dereference
golang closure catch wrong value from range
Is there autovivification for Go?

Categories

HOME
scikit-learn
twitter-bootstrap-3
apache-flink
nvd3.js
ecmascript-6
angular2-material
case
yahoo-finance
saml-2.0
sitecore
solaris
shiro
static-site
rds
gembox-spreadsheet
trac
enthought
xcodebuild
stellar.js
supervisor
speech-synthesis
frequency-distribution
3nf
qsqlquery
capistrano3
event-sourcing
job-scheduling
red5
connector
enterprise-miner
ember-cli
monit
moses
interbase
pylons
linked-data
ntp
nsurl
zend-debugger
record
deltaspike
memory-address
carriage-return
hibernate-search
jwplayer6
yowsup
xajax
raft
magento-1.9.2.4
apic
naming
x++
puredata
jide
double-click
identification
manova
podscms
page-replacement
opengl-4
arules
offline.js
gameplay-kit
django-1.10
reachability
taocp
cudd
webjars
burrows-wheeler-transform
installshield-2010
http-status-code-401
fuzzywuzzy
dynatree
oracle-spatial
flock
canalyzer
rpart
iced-coffeescript
jdk1.7
baasbox
dnssec
telepat
shopizer
public-html
adehabitathr
apache-spark-1.3
pseudo-class
mdichild
ora-00904
functional-java
alternate
buffering
menubar
synapse
windows-embedded-standard
ora-06550
code-duplication
unit-of-work
jquery-1.9
zope.interface
appjs
mapping-by-code
node-redis
screen-size
w3c-geolocation
appledoc
load-time
easyb
message-passing
data-mapping
visualj#
entitykey
product-management
ifilter
information-management
xslcompiledtransform

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App