-
Notifications
You must be signed in to change notification settings - Fork 65
rmw
In some situations we want to read a row from a cluster, modify the value and write it back to the cluster. This is achieved with a simple BeanShell Listener and some extra logic.
The first step is to create some User Define Variables. Select Thread Group -> Add -> Config Element -> User Defined Variables. We need to define two. The first, do_put, is a flag to indicate if our Get suceeded and we can do the put of the modified data. The second, cvalue, holds the modified value that we will put in the row. The screenshot shows these variables. It also shows the full experiment on the left hand side.
The CSV Data Set Config defines a file with rowid,column_name. In this file we place both valid rowids and invalid ones (99 below) that will fail the Get
1,0
1,1
1,2
1,3
1,4
2,0
2,1
2,2
2,3
2,4
99,0
99,1
99,2
99,3
99,4
4,0
The Cassandra Get is a regular one returning the column specified by the rowid and column name.
After this we insert a BeanShell Listener. Select Thread Group -> Add -> Listener -> BeanShell Listener. This contains code to
Check the status of the previous Get
If OK (status 200)
Set do_put to indicate the Put can be executed
Extract the value from Get, modify it and write it to variable cvalue
Else clear do_put to avoid Put
Next we insert an If Controller. Select Thread Group -> Logic Controller -> If Controller. This contains a very simple test of whether do_put is 1.
We then make the Put a child of this Controller. This Put uses the same rowid and cname as the Get but the modified User Defined cvalue from the BeanShell
The View Results Tree shows a Cassandra Get followed immediately by a Cassandra Put except in the case of invalid rowids where the Get failed (highlighted in red). Also looking at the Sampler data for the Put we see the Column Value written is the original data with _modified appended (also highlighted in red)
This technique can be used in many scenarios, moving data from one CF to another or purging unwanted data for example.
The jmx file for the read modify write experiment is here
A Netflix Original Production
Tech Blog | Twitter @NetflixOSS | Jobs