Skip to content

Commit

Permalink
Add direct upload config flag for Google cloud storage, fixes #177.
Browse files Browse the repository at this point in the history
  • Loading branch information
eLod committed Feb 21, 2016
1 parent 77fab6a commit 6b9e936
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/config/secor.common.properties
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ secor.gs.bucket=secor_gs
# Google cloud storage path where files are stored within the bucket.
secor.gs.path=data

# Use direct uploads
# WARNING: disables resumable uploads, files are uploaded in a single request
# This may help prevent IOException: insufficient data written,
# see https://github.com/pinterest/secor/issues/177
# https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload
secor.gs.upload.direct=false

# Zookeeper config.
zookeeper.session.timeout.ms=3000
zookeeper.sync.time.ms=200
Expand Down
9 changes: 8 additions & 1 deletion src/main/config/secor.dev.gs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ secor.gs.path=data

# Application credentials configuration file
# https://developers.google.com/identity/protocols/application-default-credentials
secor.gs.credentials.path=google_app_credentials.json
secor.gs.credentials.path=google_app_credentials.json

# Use direct uploads
# WARNING: disables resumable uploads, files are uploaded in a single request
# This may help prevent IOException: insufficient data written,
# see https://github.com/pinterest/secor/issues/177
# https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload
secor.gs.upload.direct=false
4 changes: 4 additions & 0 deletions src/main/java/com/pinterest/secor/common/SecorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ public int getGsReadTimeoutInMs() {
return getInt("secor.gs.read.timeout.ms", 3 * 60000);
}

public boolean getGsDirectUpload() {
return getBoolean("secor.gs.upload.direct");
}

public int getFinalizerDelaySeconds() {
return getInt("partitioner.finalizer.delay.seconds");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Handle<?> upload(LogFilePath localPath) throws Exception {
final String gsBucket = mConfig.getGsBucket();
final String gsKey = localPath.withPrefix(mConfig.getGsPath()).getLogFilePath();
final File localFile = new File(localPath.getLogFilePath());
final boolean directUpload = mConfig.getGsDirectUpload();

LOG.info("uploading file {} to gs://{}/{}", localFile, gsBucket, gsKey);

Expand All @@ -81,6 +82,10 @@ public void run() {
try {
Storage.Objects.Insert request = mClient.objects().insert(gsBucket, storageObject, storageContent);

if (directUpload) {
request.getMediaHttpUploader().setDirectUploadEnabled(true);
}

request.getMediaHttpUploader().setProgressListener(new MediaHttpUploaderProgressListener() {
@Override
public void progressChanged(MediaHttpUploader uploader) throws IOException {
Expand Down

0 comments on commit 6b9e936

Please sign in to comment.