-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Souvik Bose <souvbose@amazon.com>
- Loading branch information
Showing
18 changed files
with
883 additions
and
179 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
47 changes: 47 additions & 0 deletions
47
...a/org/opensearch/dataprepper/plugins/kinesis/source/converter/KinesisRecordConverter.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,47 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.kinesis.source.converter; | ||
|
||
import org.opensearch.dataprepper.model.codec.InputCodec; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import software.amazon.kinesis.retrieval.KinesisClientRecord; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public class KinesisRecordConverter { | ||
|
||
private final InputCodec codec; | ||
|
||
public KinesisRecordConverter(final InputCodec codec) { | ||
this.codec = codec; | ||
} | ||
|
||
public List<Record<Event>> convert(List<KinesisClientRecord> kinesisClientRecords) throws IOException { | ||
List<Record<Event>> records = new ArrayList<>(); | ||
for (KinesisClientRecord record : kinesisClientRecords) { | ||
processRecord(record, records::add); | ||
} | ||
return records; | ||
} | ||
|
||
private void processRecord(KinesisClientRecord record, Consumer<Record<Event>> eventConsumer) throws IOException { | ||
// Read bytebuffer | ||
byte[] arr = new byte[record.data().remaining()]; | ||
record.data().get(arr); | ||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(arr); | ||
codec.parse(byteArrayInputStream, eventConsumer); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...rg/opensearch/dataprepper/plugins/kinesis/source/processor/KinesisCheckpointerRecord.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,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.kinesis.source.processor; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import software.amazon.kinesis.processor.RecordProcessorCheckpointer; | ||
import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber; | ||
|
||
@Builder | ||
@Getter | ||
@Setter | ||
public class KinesisCheckpointerRecord { | ||
private RecordProcessorCheckpointer checkpointer; | ||
private ExtendedSequenceNumber extendedSequenceNumber; | ||
private boolean readyToCheckpoint; | ||
} |
68 changes: 68 additions & 0 deletions
68
...g/opensearch/dataprepper/plugins/kinesis/source/processor/KinesisCheckpointerTracker.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,68 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.kinesis.source.processor; | ||
|
||
import software.amazon.kinesis.processor.RecordProcessorCheckpointer; | ||
import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class KinesisCheckpointerTracker { | ||
private final Map<ExtendedSequenceNumber, KinesisCheckpointerRecord> checkpointerRecordList = new LinkedHashMap<>(); | ||
|
||
public synchronized void addRecordForCheckpoint(final ExtendedSequenceNumber extendedSequenceNumber, | ||
final RecordProcessorCheckpointer checkpointer) { | ||
checkpointerRecordList.put(extendedSequenceNumber, KinesisCheckpointerRecord.builder() | ||
.extendedSequenceNumber(extendedSequenceNumber) | ||
.checkpointer(checkpointer) | ||
.readyToCheckpoint(false) | ||
.build()); | ||
} | ||
|
||
public synchronized void markSequenceNumberForCheckpoint(final ExtendedSequenceNumber extendedSequenceNumber) { | ||
if (!checkpointerRecordList.containsKey(extendedSequenceNumber)) { | ||
throw new IllegalArgumentException("checkpointer not available"); | ||
} | ||
checkpointerRecordList.get(extendedSequenceNumber).setReadyToCheckpoint(true); | ||
} | ||
|
||
public synchronized Optional<KinesisCheckpointerRecord> getLatestAvailableCheckpointRecord() { | ||
Optional<KinesisCheckpointerRecord> kinesisCheckpointerRecordOptional = Optional.empty(); | ||
List<ExtendedSequenceNumber> toRemoveRecords = new ArrayList<>(); | ||
|
||
for (Map.Entry<ExtendedSequenceNumber, KinesisCheckpointerRecord> entry: checkpointerRecordList.entrySet()) { | ||
KinesisCheckpointerRecord kinesisCheckpointerRecord = entry.getValue(); | ||
|
||
// Break out of the loop on the first record which is not ready for checkpoint | ||
if (!kinesisCheckpointerRecord.isReadyToCheckpoint()) { | ||
break; | ||
} | ||
|
||
kinesisCheckpointerRecordOptional = Optional.of(kinesisCheckpointerRecord); | ||
toRemoveRecords.add(entry.getKey()); | ||
} | ||
|
||
//Cleanup the ones which are already marked for checkpoint | ||
for (ExtendedSequenceNumber extendedSequenceNumber: toRemoveRecords) { | ||
checkpointerRecordList.remove(extendedSequenceNumber); | ||
} | ||
|
||
return kinesisCheckpointerRecordOptional; | ||
} | ||
|
||
public synchronized int size() { | ||
return checkpointerRecordList.size(); | ||
} | ||
} |
Oops, something went wrong.