forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds S3 sink compression. Resolves opensearch-project#3130.
Signed-off-by: David Venable <[email protected]>
- Loading branch information
Showing
18 changed files
with
578 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...c/main/java/org/opensearch/dataprepper/plugins/sink/s3/accumulator/CompressionBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3.accumulator; | ||
|
||
import org.opensearch.dataprepper.plugins.sink.s3.compression.CompressionEngine; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.Objects; | ||
|
||
class CompressionBuffer implements Buffer { | ||
private final Buffer innerBuffer; | ||
private final CompressionEngine compressionEngine; | ||
private volatile OutputStream outputStream; | ||
|
||
CompressionBuffer(final Buffer innerBuffer, final CompressionEngine compressionEngine) { | ||
this.innerBuffer = Objects.requireNonNull(innerBuffer); | ||
this.compressionEngine = Objects.requireNonNull(compressionEngine); | ||
} | ||
|
||
@Override | ||
public long getSize() { | ||
return innerBuffer.getSize(); | ||
} | ||
|
||
@Override | ||
public int getEventCount() { | ||
return innerBuffer.getEventCount(); | ||
} | ||
|
||
@Override | ||
public long getDuration() { | ||
return innerBuffer.getDuration(); | ||
} | ||
|
||
@Override | ||
public void flushToS3(final S3Client s3Client, final String bucket, final String key) { | ||
innerBuffer.flushToS3(s3Client, bucket, key); | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream() { | ||
if(outputStream == null) { | ||
synchronized (this) { | ||
if(outputStream == null) { | ||
final OutputStream innerBufferOutputStream = innerBuffer.getOutputStream(); | ||
try { | ||
outputStream = compressionEngine.createOutputStream(innerBufferOutputStream); | ||
} catch (final IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} | ||
return outputStream; | ||
} | ||
|
||
@Override | ||
public void setEventCount(final int eventCount) { | ||
innerBuffer.setEventCount(eventCount); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...java/org/opensearch/dataprepper/plugins/sink/s3/accumulator/CompressionBufferFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3.accumulator; | ||
|
||
import org.opensearch.dataprepper.plugins.sink.s3.compression.CompressionEngine; | ||
|
||
import java.util.Objects; | ||
|
||
public class CompressionBufferFactory implements BufferFactory { | ||
private final BufferFactory innerBufferFactory; | ||
private final CompressionEngine compressionEngine; | ||
|
||
public CompressionBufferFactory(final BufferFactory innerBufferFactory, final CompressionEngine compressionEngine) { | ||
this.innerBufferFactory = Objects.requireNonNull(innerBufferFactory); | ||
this.compressionEngine = Objects.requireNonNull(compressionEngine); | ||
} | ||
|
||
@Override | ||
public Buffer getBuffer() { | ||
return new CompressionBuffer(innerBufferFactory.getBuffer(), compressionEngine); | ||
} | ||
} |
Oops, something went wrong.