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
a70aa676
Unverified
Commit
a70aa676
authored
9 years ago
by
Jason Tedor
Browse files
Options
Downloads
Patches
Plain Diff
[elasticsearch] Cleanup code formatting
parent
5bb05744
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
elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java
+16
-33
16 additions, 33 deletions
.../src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java
with
16 additions
and
33 deletions
elasticsearch/src/main/java/com/yahoo/ycsb/db/ElasticsearchClient.java
+
16
−
33
View file @
a70aa676
...
...
@@ -22,7 +22,6 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import
static
org
.
elasticsearch
.
index
.
query
.
QueryBuilders
.
rangeQuery
;
import
static
org
.
elasticsearch
.
node
.
NodeBuilder
.
nodeBuilder
;
import
com.yahoo.ycsb.ByteIterator
;
import
com.yahoo.ycsb.DB
;
import
com.yahoo.ycsb.DBException
;
...
...
@@ -84,18 +83,15 @@ public class ElasticsearchClient extends DB {
public
void
init
()
throws
DBException
{
Properties
props
=
getProperties
();
this
.
indexKey
=
props
.
getProperty
(
"es.index.key"
,
DEFAULT_INDEX_KEY
);
String
clusterName
=
props
.
getProperty
(
"es.cluster.name"
,
DEFAULT_CLUSTER_NAME
);
String
clusterName
=
props
.
getProperty
(
"es.cluster.name"
,
DEFAULT_CLUSTER_NAME
);
int
numberOfShards
=
parseIntegerProperty
(
props
,
"es.number_of_shards"
,
NUMBER_OF_SHARDS
);
int
numberOfReplicas
=
parseIntegerProperty
(
props
,
"es.number_of_replicas"
,
NUMBER_OF_REPLICAS
);
// Check if transport client needs to be used (To connect to multiple
// elasticsearch nodes)
remoteMode
=
Boolean
.
parseBoolean
(
props
.
getProperty
(
"es.remote"
,
"false"
));
Boolean
newdb
=
Boolean
.
parseBoolean
(
props
.
getProperty
(
"es.newdb"
,
"false"
));
remoteMode
=
Boolean
.
parseBoolean
(
props
.
getProperty
(
"es.remote"
,
"false"
));
Boolean
newdb
=
Boolean
.
parseBoolean
(
props
.
getProperty
(
"es.newdb"
,
"false"
));
Builder
settings
=
Settings
.
settingsBuilder
()
.
put
(
"cluster.name"
,
clusterName
)
.
put
(
"node.local"
,
Boolean
.
toString
(!
remoteMode
))
...
...
@@ -104,10 +100,8 @@ public class ElasticsearchClient extends DB {
// if properties file contains elasticsearch user defined properties
// add it to the settings file (will overwrite the defaults).
settings
.
put
(
props
);
System
.
out
.
println
(
"Elasticsearch starting node = "
+
settings
.
get
(
"cluster.name"
));
System
.
out
.
println
(
"Elasticsearch node path.home = "
+
settings
.
get
(
"path.home"
));
System
.
out
.
println
(
"Elasticsearch starting node = "
+
settings
.
get
(
"cluster.name"
));
System
.
out
.
println
(
"Elasticsearch node path.home = "
+
settings
.
get
(
"path.home"
));
System
.
out
.
println
(
"Elasticsearch Remote Mode = "
+
remoteMode
);
// Remote mode support for connecting to remote elasticsearch cluster
if
(
remoteMode
)
{
...
...
@@ -116,13 +110,9 @@ public class ElasticsearchClient extends DB {
.
put
(
"client.transport.ping_timeout"
,
"30s"
)
.
put
(
"client.transport.nodes_sampler_interval"
,
"30s"
);
// Default it to localhost:9300
String
[]
nodeList
=
props
.
getProperty
(
"es.hosts.list"
,
DEFAULT_REMOTE_HOST
)
.
split
(
","
);
System
.
out
.
println
(
"Elasticsearch Remote Hosts = "
+
props
.
getProperty
(
"es.hosts.list"
,
DEFAULT_REMOTE_HOST
));
TransportClient
tClient
=
TransportClient
.
builder
()
.
settings
(
settings
).
build
();
String
[]
nodeList
=
props
.
getProperty
(
"es.hosts.list"
,
DEFAULT_REMOTE_HOST
).
split
(
","
);
System
.
out
.
println
(
"Elasticsearch Remote Hosts = "
+
props
.
getProperty
(
"es.hosts.list"
,
DEFAULT_REMOTE_HOST
));
TransportClient
tClient
=
TransportClient
.
builder
().
settings
(
settings
).
build
();
for
(
String
h
:
nodeList
)
{
String
[]
nodes
=
h
.
split
(
":"
);
try
{
...
...
@@ -200,15 +190,13 @@ public class ElasticsearchClient extends DB {
try
{
final
XContentBuilder
doc
=
jsonBuilder
().
startObject
();
for
(
Entry
<
String
,
String
>
entry
:
StringByteIterator
.
getStringMap
(
values
)
.
entrySet
())
{
for
(
Entry
<
String
,
String
>
entry
:
StringByteIterator
.
getStringMap
(
values
).
entrySet
())
{
doc
.
field
(
entry
.
getKey
(),
entry
.
getValue
());
}
doc
.
endObject
();
client
.
prepareIndex
(
indexKey
,
table
,
key
).
setSource
(
doc
).
execute
()
.
actionGet
();
client
.
prepareIndex
(
indexKey
,
table
,
key
).
setSource
(
doc
).
execute
().
actionGet
();
return
Status
.
OK
;
}
catch
(
Exception
e
)
{
...
...
@@ -256,8 +244,7 @@ public class ElasticsearchClient extends DB {
public
Status
read
(
String
table
,
String
key
,
Set
<
String
>
fields
,
HashMap
<
String
,
ByteIterator
>
result
)
{
try
{
final
GetResponse
response
=
client
.
prepareGet
(
indexKey
,
table
,
key
).
execute
().
actionGet
();
final
GetResponse
response
=
client
.
prepareGet
(
indexKey
,
table
,
key
).
execute
().
actionGet
();
if
(
response
.
isExists
())
{
if
(
fields
!=
null
)
{
...
...
@@ -297,17 +284,14 @@ public class ElasticsearchClient extends DB {
public
Status
update
(
String
table
,
String
key
,
HashMap
<
String
,
ByteIterator
>
values
)
{
try
{
final
GetResponse
response
=
client
.
prepareGet
(
indexKey
,
table
,
key
).
execute
().
actionGet
();
final
GetResponse
response
=
client
.
prepareGet
(
indexKey
,
table
,
key
).
execute
().
actionGet
();
if
(
response
.
isExists
())
{
for
(
Entry
<
String
,
String
>
entry
:
StringByteIterator
.
getStringMap
(
values
).
entrySet
())
{
for
(
Entry
<
String
,
String
>
entry
:
StringByteIterator
.
getStringMap
(
values
).
entrySet
())
{
response
.
getSource
().
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
client
.
prepareIndex
(
indexKey
,
table
,
key
)
.
setSource
(
response
.
getSource
()).
execute
().
actionGet
();
client
.
prepareIndex
(
indexKey
,
table
,
key
).
setSource
(
response
.
getSource
()).
execute
().
actionGet
();
return
Status
.
OK
;
}
...
...
@@ -351,11 +335,10 @@ public class ElasticsearchClient extends DB {
HashMap
<
String
,
ByteIterator
>
entry
;
for
(
SearchHit
hit
:
response
.
getHits
())
{
entry
=
new
HashMap
<
String
,
ByteIterator
>(
fields
.
size
());
entry
=
new
HashMap
<>(
fields
.
size
());
for
(
String
field
:
fields
)
{
entry
.
put
(
field
,
new
StringByteIterator
((
String
)
hit
.
getSource
().
get
(
field
)));
entry
.
put
(
field
,
new
StringByteIterator
((
String
)
hit
.
getSource
().
get
(
field
)));
}
result
.
add
(
entry
);
...
...
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