Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
YCSB
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
a1d5f707
There was an error fetching the commit references. Please try again later.
Commit
a1d5f707
authored
13 years ago
by
Russell Sears
Browse files
Options
Downloads
Patches
Plain Diff
refactor core workload to reduce redundant key and field generation code
parent
2aea7d50
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
src/com/yahoo/ycsb/workloads/CoreWorkload.java
+44
-67
44 additions, 67 deletions
src/com/yahoo/ycsb/workloads/CoreWorkload.java
with
44 additions
and
67 deletions
src/com/yahoo/ycsb/workloads/CoreWorkload.java
+
44
−
67
View file @
a1d5f707
...
@@ -411,6 +411,33 @@ public class CoreWorkload extends Workload
...
@@ -411,6 +411,33 @@ public class CoreWorkload extends Workload
}
}
}
}
public
String
buildKeyName
(
int
keynum
)
{
if
(!
orderedinserts
)
{
keynum
=
Utils
.
hash
(
keynum
);
}
return
"user"
+
keynum
;
}
HashMap
<
String
,
ByteIterator
>
buildValues
()
{
HashMap
<
String
,
ByteIterator
>
values
=
new
HashMap
<
String
,
ByteIterator
>();
for
(
int
i
=
0
;
i
<
fieldcount
;
i
++)
{
String
fieldkey
=
"field"
+
i
;
ByteIterator
data
=
new
RandomByteIterator
(
fieldlengthgenerator
.
nextInt
());
values
.
put
(
fieldkey
,
data
);
}
return
values
;
}
HashMap
<
String
,
ByteIterator
>
buildUpdate
()
{
//update a random field
HashMap
<
String
,
ByteIterator
>
values
=
new
HashMap
<
String
,
ByteIterator
>();
String
fieldname
=
"field"
+
fieldchooser
.
nextString
();
ByteIterator
data
=
new
RandomByteIterator
(
fieldlengthgenerator
.
nextInt
());
values
.
put
(
fieldname
,
data
);
return
values
;
}
/**
/**
* Do one insert operation. Because it will be called concurrently from multiple client threads, this
* Do one insert operation. Because it will be called concurrently from multiple client threads, this
* function must be thread safe. However, avoid synchronized, or the threads will block waiting for each
* function must be thread safe. However, avoid synchronized, or the threads will block waiting for each
...
@@ -420,19 +447,8 @@ public class CoreWorkload extends Workload
...
@@ -420,19 +447,8 @@ public class CoreWorkload extends Workload
public
boolean
doInsert
(
DB
db
,
Object
threadstate
)
public
boolean
doInsert
(
DB
db
,
Object
threadstate
)
{
{
int
keynum
=
keysequence
.
nextInt
();
int
keynum
=
keysequence
.
nextInt
();
if
(!
orderedinserts
)
String
dbkey
=
buildKeyName
(
keynum
);
{
HashMap
<
String
,
ByteIterator
>
values
=
buildValues
();
keynum
=
Utils
.
hash
(
keynum
);
}
String
dbkey
=
"user"
+
keynum
;
HashMap
<
String
,
ByteIterator
>
values
=
new
HashMap
<
String
,
ByteIterator
>();
for
(
int
i
=
0
;
i
<
fieldcount
;
i
++)
{
String
fieldkey
=
"field"
+
i
;
ByteIterator
data
=
new
RandomByteIterator
(
fieldlengthgenerator
.
nextInt
());
values
.
put
(
fieldkey
,
data
);
}
if
(
db
.
insert
(
table
,
dbkey
,
values
)
==
0
)
if
(
db
.
insert
(
table
,
dbkey
,
values
)
==
0
)
return
true
;
return
true
;
else
else
...
@@ -483,12 +499,8 @@ public class CoreWorkload extends Workload
...
@@ -483,12 +499,8 @@ public class CoreWorkload extends Workload
}
}
while
(
keynum
>
transactioninsertkeysequence
.
lastInt
());
while
(
keynum
>
transactioninsertkeysequence
.
lastInt
());
if
(!
orderedinserts
)
String
keyname
=
buildKeyName
(
keynum
);
{
keynum
=
Utils
.
hash
(
keynum
);
}
String
keyname
=
"user"
+
keynum
;
HashSet
<
String
>
fields
=
null
;
HashSet
<
String
>
fields
=
null
;
if
(!
readallfields
)
if
(!
readallfields
)
...
@@ -513,11 +525,7 @@ public class CoreWorkload extends Workload
...
@@ -513,11 +525,7 @@ public class CoreWorkload extends Workload
}
}
while
(
keynum
>
transactioninsertkeysequence
.
lastInt
());
while
(
keynum
>
transactioninsertkeysequence
.
lastInt
());
if
(!
orderedinserts
)
String
keyname
=
buildKeyName
(
keynum
);
{
keynum
=
Utils
.
hash
(
keynum
);
}
String
keyname
=
"user"
+
keynum
;
HashSet
<
String
>
fields
=
null
;
HashSet
<
String
>
fields
=
null
;
...
@@ -530,24 +538,17 @@ public class CoreWorkload extends Workload
...
@@ -530,24 +538,17 @@ public class CoreWorkload extends Workload
fields
.
add
(
fieldname
);
fields
.
add
(
fieldname
);
}
}
HashMap
<
String
,
ByteIterator
>
values
=
new
HashMap
<
String
,
ByteIterator
>()
;
HashMap
<
String
,
ByteIterator
>
values
;
if
(
writeallfields
)
if
(
writeallfields
)
{
{
//new data for all the fields
//new data for all the fields
for
(
int
i
=
0
;
i
<
fieldcount
;
i
++)
values
=
buildValues
();
{
String
fieldname
=
"field"
+
i
;
ByteIterator
data
=
new
RandomByteIterator
(
fieldlengthgenerator
.
nextInt
());
values
.
put
(
fieldname
,
data
);
}
}
}
else
else
{
{
//update a random field
//update a random field
String
fieldname
=
"field"
+
fieldchooser
.
nextString
();
values
=
buildUpdate
();
ByteIterator
data
=
new
RandomByteIterator
(
fieldlengthgenerator
.
nextInt
());
values
.
put
(
fieldname
,
data
);
}
}
//do the transaction
//do the transaction
...
@@ -573,11 +574,7 @@ public class CoreWorkload extends Workload
...
@@ -573,11 +574,7 @@ public class CoreWorkload extends Workload
}
}
while
(
keynum
>
transactioninsertkeysequence
.
lastInt
());
while
(
keynum
>
transactioninsertkeysequence
.
lastInt
());
if
(!
orderedinserts
)
String
startkeyname
=
buildKeyName
(
keynum
);
{
keynum
=
Utils
.
hash
(
keynum
);
}
String
startkeyname
=
"user"
+
keynum
;
//choose a random scan length
//choose a random scan length
int
len
=
scanlength
.
nextInt
();
int
len
=
scanlength
.
nextInt
();
...
@@ -606,30 +603,19 @@ public class CoreWorkload extends Workload
...
@@ -606,30 +603,19 @@ public class CoreWorkload extends Workload
}
}
while
(
keynum
>
transactioninsertkeysequence
.
lastInt
());
while
(
keynum
>
transactioninsertkeysequence
.
lastInt
());
if
(!
orderedinserts
)
String
keyname
=
buildKeyName
(
keynum
);
{
keynum
=
Utils
.
hash
(
keynum
);
}
String
keyname
=
"user"
+
keynum
;
HashMap
<
String
,
ByteIterator
>
values
=
new
HashMap
<
String
,
ByteIterator
>()
;
HashMap
<
String
,
ByteIterator
>
values
;
if
(
writeallfields
)
if
(
writeallfields
)
{
{
//new data for all the fields
//new data for all the fields
for
(
int
i
=
0
;
i
<
fieldcount
;
i
++)
values
=
buildValues
();
{
String
fieldname
=
"field"
+
i
;
ByteIterator
data
=
new
RandomByteIterator
(
fieldlengthgenerator
.
nextInt
());
values
.
put
(
fieldname
,
data
);
}
}
}
else
else
{
{
//update a random field
//update a random field
String
fieldname
=
"field"
+
fieldchooser
.
nextString
();
values
=
buildUpdate
();
ByteIterator
data
=
new
RandomByteIterator
(
fieldlengthgenerator
.
nextInt
());
values
.
put
(
fieldname
,
data
);
}
}
db
.
update
(
table
,
keyname
,
values
);
db
.
update
(
table
,
keyname
,
values
);
...
@@ -639,19 +625,10 @@ public class CoreWorkload extends Workload
...
@@ -639,19 +625,10 @@ public class CoreWorkload extends Workload
{
{
//choose the next key
//choose the next key
int
keynum
=
transactioninsertkeysequence
.
nextInt
();
int
keynum
=
transactioninsertkeysequence
.
nextInt
();
if
(!
orderedinserts
)
{
String
dbkey
=
buildKeyName
(
keynum
);
keynum
=
Utils
.
hash
(
keynum
);
}
HashMap
<
String
,
ByteIterator
>
values
=
buildValues
();
String
dbkey
=
"user"
+
keynum
;
HashMap
<
String
,
ByteIterator
>
values
=
new
HashMap
<
String
,
ByteIterator
>();
for
(
int
i
=
0
;
i
<
fieldcount
;
i
++)
{
String
fieldkey
=
"field"
+
i
;
ByteIterator
data
=
new
RandomByteIterator
(
fieldlengthgenerator
.
nextInt
());
values
.
put
(
fieldkey
,
data
);
}
db
.
insert
(
table
,
dbkey
,
values
);
db
.
insert
(
table
,
dbkey
,
values
);
}
}
}
}
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