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
bf8a3475
Commit
bf8a3475
authored
9 years ago
by
ivan
Browse files
Options
Downloads
Patches
Plain Diff
using atomicinteger to cleanup
parent
07824994
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
s3/src/main/java/com/yahoo/ycsb/db/S3Client.java
+17
-12
17 additions, 12 deletions
s3/src/main/java/com/yahoo/ycsb/db/S3Client.java
with
17 additions
and
12 deletions
s3/src/main/java/com/yahoo/ycsb/db/S3Client.java
+
17
−
12
View file @
bf8a3475
...
...
@@ -13,6 +13,7 @@ import java.util.Vector;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.util.*
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
com.yahoo.ycsb.ByteArrayByteIterator
;
import
com.yahoo.ycsb.ByteIterator
;
...
...
@@ -64,6 +65,7 @@ public class S3Client extends DB {
private
static
BasicAWSCredentials
s3Credentials
;
private
static
AmazonS3Client
s3Client
;
private
static
ClientConfiguration
clientConfig
;
private
static
final
AtomicInteger
INIT_COUNT
=
new
AtomicInteger
(
0
);
/**
* Cleanup any state for this storage.
...
...
@@ -71,11 +73,13 @@ public class S3Client extends DB {
*/
@Override
public
void
cleanup
()
throws
DBException
{
if
(
this
.
s3Client
!=
null
)
{
if
(
INIT_COUNT
.
decrementAndGet
()
==
0
)
{
try
{
this
.
s3Client
=
null
;
this
.
s3Client
.
shutdown
()
;
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
finally
{
this
.
s3Client
=
null
;
}
}
}
...
...
@@ -105,22 +109,23 @@ public class S3Client extends DB {
*/
@Override
public
void
init
()
throws
DBException
{
INIT_COUNT
.
incrementAndGet
();
synchronized
(
S3Client
.
class
){
Properties
props
=
getProperties
();
accessKeyId
=
props
.
getProperty
(
"s3.accessKeyId"
,
"accessKeyId"
);
secretKey
=
props
.
getProperty
(
"s3.secretKey"
,
"secretKey"
);
endPoint
=
props
.
getProperty
(
"s3.endPoint"
,
"s3.amazonaws.com"
);
region
=
props
.
getProperty
(
"s3.region"
,
"us-east-1"
);
maxErrorRetry
=
props
.
getProperty
(
"s3.maxErrorRetry"
,
"15"
);
System
.
out
.
println
(
"Inizializing the S3 connection"
);
s3Credentials
=
new
BasicAWSCredentials
(
accessKeyId
,
secretKey
);
clientConfig
=
new
ClientConfiguration
();
clientConfig
.
setMaxErrorRetry
(
Integer
.
parseInt
(
maxErrorRetry
));
if
(
s3Client
!=
null
)
{
System
.
out
.
println
(
"Reusing the same client"
);
return
;
}
try
{
Properties
props
=
getProperties
();
accessKeyId
=
props
.
getProperty
(
"s3.accessKeyId"
,
"accessKeyId"
);
secretKey
=
props
.
getProperty
(
"s3.secretKey"
,
"secretKey"
);
endPoint
=
props
.
getProperty
(
"s3.endPoint"
,
"s3.amazonaws.com"
);
region
=
props
.
getProperty
(
"s3.region"
,
"us-east-1"
);
maxErrorRetry
=
props
.
getProperty
(
"s3.maxErrorRetry"
,
"15"
);
System
.
out
.
println
(
"Inizializing the S3 connection"
);
s3Credentials
=
new
BasicAWSCredentials
(
accessKeyId
,
secretKey
);
clientConfig
=
new
ClientConfiguration
();
clientConfig
.
setMaxErrorRetry
(
Integer
.
parseInt
(
maxErrorRetry
));
s3Client
=
new
AmazonS3Client
(
s3Credentials
,
clientConfig
);
s3Client
.
setRegion
(
Region
.
getRegion
(
Regions
.
fromName
(
region
)));
s3Client
.
setEndpoint
(
endPoint
);
...
...
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