Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F2617561
read
Eevans (Eric Evans)
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
Eevans
Sep 18 2015, 8:40 PM
2015-09-18 20:40:12 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
read
View Options
#!/usr/bin/env python
from
cassandra
import
ConsistencyLevel
from
cassandra.auth
import
PlainTextAuthProvider
from
cassandra.cluster
import
Cluster
from
cassandra.policies
import
DCAwareRoundRobinPolicy
from
cassandra.query
import
SimpleStatement
from
uuid
import
UUID
import
logging
import
sys
logging
.
basicConfig
(
level
=
logging
.
INFO
)
def
data
():
for
ln
in
sys
.
stdin
.
readlines
():
yield
tuple
(
ln
.
strip
()
.
split
())
if
__name__
==
'__main__'
:
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
"write/read test data"
)
parser
.
add_argument
(
"hostname"
,
type
=
str
,
help
=
"Cassandra node hostname"
)
parser
.
add_argument
(
"--local-dc"
,
type
=
str
,
default
=
"eqiad"
,
help
=
"Local datacenter"
)
args
=
parser
.
parse_args
()
auth_provider
=
PlainTextAuthProvider
(
username
=
'cassandra'
,
password
=
'cassandra'
)
policy
=
DCAwareRoundRobinPolicy
(
local_dc
=
args
.
local_dc
)
cluster
=
Cluster
([
args
.
hostname
],
load_balancing_policy
=
policy
,
auth_provider
=
auth_provider
)
session
=
cluster
.
connect
(
"keyspace1"
)
if
sys
.
argv
[
0
]
.
endswith
(
'write'
):
logging
.
info
(
"writing..."
)
insert
=
session
.
prepare
(
"INSERT INTO keyspace1.standard1 (id,val) VALUES (?, ?)"
)
insert
.
consistency_level
=
ConsistencyLevel
.
LOCAL_QUORUM
for
(
id
,
val
)
in
data
():
session
.
execute
(
insert
,
(
UUID
(
id
),
int
(
val
)))
logging
.
info
(
"writing complete."
)
else
:
logging
.
info
(
"verifying..."
)
select
=
session
.
prepare
(
"SELECT val FROM keyspace1.standard1 WHERE id = ?"
)
select
.
consistency_level
=
ConsistencyLevel
.
LOCAL_QUORUM
for
(
id
,
val
)
in
data
():
row
=
session
.
execute
(
select
,
(
UUID
(
id
),))[
0
]
assert
row
.
val
==
int
(
val
)
logging
.
info
(
"verification complete."
)
File Metadata
Details
Attached
Mime Type
text/x-python
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2630745
Default Alt Text
read (1 KB)
Attached To
Mode
T108613: Set up multi-DC replication for Cassandra
Attached
Detach File
Event Timeline
Log In to Comment