Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
YCSB
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adnan Ahmad
YCSB
Commits
a591975d
Commit
a591975d
authored
4 years ago
by
Adnan Ahmad
Browse files
Options
Downloads
Patches
Plain Diff
implemented scan and cleanup
parent
547501f5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
zookeeper/src/main/java/site/ycsb/db/ZookeeperClient.java
+58
-6
58 additions, 6 deletions
zookeeper/src/main/java/site/ycsb/db/ZookeeperClient.java
with
58 additions
and
6 deletions
zookeeper/src/main/java/site/ycsb/db/ZookeeperClient.java
+
58
−
6
View file @
a591975d
...
@@ -5,18 +5,16 @@ import org.apache.zookeeper.KeeperException;
...
@@ -5,18 +5,16 @@ import org.apache.zookeeper.KeeperException;
import
org.apache.zookeeper.ZooDefs
;
import
org.apache.zookeeper.ZooDefs
;
import
org.apache.zookeeper.ZooKeeper
;
import
org.apache.zookeeper.ZooKeeper
;
import
org.apache.zookeeper.data.Stat
;
import
org.apache.zookeeper.data.Stat
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
site.ycsb.*
;
import
site.ycsb.*
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.*
;
import
java.util.Map
;
import
java.util.Set
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
java.util.Vector
;
/**
/**
* A client that can be used by YCSB to work with Zookeeper.
* A client that can be used by YCSB to work with Zookeeper.
*/
*/
...
@@ -24,6 +22,8 @@ public class ZookeeperClient extends DB {
...
@@ -24,6 +22,8 @@ public class ZookeeperClient extends DB {
private
static
ZooKeeper
zooKeeper
;
private
static
ZooKeeper
zooKeeper
;
private
static
ZKConnection
zkConnection
;
private
static
ZKConnection
zkConnection
;
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ZookeeperClient
.
class
);
public
void
init
()
throws
DBException
{
public
void
init
()
throws
DBException
{
zkConnection
=
new
ZKConnection
();
zkConnection
=
new
ZKConnection
();
...
@@ -65,7 +65,38 @@ public class ZookeeperClient extends DB {
...
@@ -65,7 +65,38 @@ public class ZookeeperClient extends DB {
@Override
@Override
public
Status
scan
(
String
table
,
String
startkey
,
public
Status
scan
(
String
table
,
String
startkey
,
int
recordcount
,
Set
<
String
>
fields
,
Vector
<
HashMap
<
String
,
ByteIterator
>>
result
)
{
int
recordcount
,
Set
<
String
>
fields
,
Vector
<
HashMap
<
String
,
ByteIterator
>>
result
)
{
return
null
;
try
{
List
<
String
>
children
=
zooKeeper
.
getChildren
(
"/"
,
true
);
Collections
.
sort
(
children
);
// go through all children to find start key
for
(
int
i
=
0
;
i
<
children
.
size
();
i
++)
{
if
(
children
.
get
(
i
).
equals
(
startkey
))
{
// make sure the number of records left is greater or equal to recordcount
if
(
children
.
size
()
-
i
<
recordcount
)
{
return
Status
.
ERROR
;
}
// read all records
for
(
int
j
=
i
;
j
<
recordcount
+
i
;
j
++)
{
HashMap
<
String
,
ByteIterator
>
m
=
new
HashMap
<>();
Status
status
=
read
(
table
,
children
.
get
(
j
),
fields
,
m
);
// make sure the status is ok
if
(
status
!=
Status
.
OK
)
{
return
status
;
}
result
.
add
(
m
);
}
}
}
}
catch
(
KeeperException
|
InterruptedException
e
)
{
e
.
printStackTrace
();
}
return
Status
.
OK
;
}
}
@Override
@Override
...
@@ -132,9 +163,29 @@ public class ZookeeperClient extends DB {
...
@@ -132,9 +163,29 @@ public class ZookeeperClient extends DB {
}
catch
(
InterruptedException
|
KeeperException
e
)
{
}
catch
(
InterruptedException
|
KeeperException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
return
Status
.
OK
;
return
Status
.
OK
;
}
}
@Override
public
void
cleanup
()
{
try
{
List
<
String
>
children
=
zooKeeper
.
getChildren
(
"/"
,
true
);
// delete all znodes except for zookeeper znode
for
(
String
child
:
children
)
{
if
(!
child
.
equals
(
"zookeeper"
))
{
// get pathStat of child znode
Stat
pathStat
=
checkExists
(
child
);
zooKeeper
.
delete
(
prefixKeyWithSlash
(
child
),
pathStat
.
getVersion
());
}
}
}
catch
(
KeeperException
|
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
// all znodes start with backslash, so start key with backslash
// all znodes start with backslash, so start key with backslash
private
String
prefixKeyWithSlash
(
String
key
)
{
private
String
prefixKeyWithSlash
(
String
key
)
{
return
(
"/"
+
key
);
return
(
"/"
+
key
);
...
@@ -155,4 +206,5 @@ public class ZookeeperClient extends DB {
...
@@ -155,4 +206,5 @@ public class ZookeeperClient extends DB {
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment